Subversion Repositories SmartDukaan

Rev

Rev 22165 | Rev 22172 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21561 ashik.ali 1
package com.spice.profitmandi.web.config;
21555 kshitij.so 2
 
3
import java.io.IOException;
4
import java.util.Properties;
5
 
6
import org.slf4j.Logger;
7
import org.slf4j.LoggerFactory;
22171 amit.gupta 8
import org.springframework.beans.factory.annotation.Value;
21555 kshitij.so 9
import org.springframework.context.annotation.Bean;
10
import org.springframework.context.annotation.ComponentScan;
11
import org.springframework.context.annotation.Configuration;
12
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
13
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
14
import org.springframework.core.io.ClassPathResource;
15
import org.springframework.core.io.Resource;
16
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
21625 kshitij.so 17
import org.springframework.web.servlet.ViewResolver;
18
import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
19
import org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver;
21555 kshitij.so 20
 
22171 amit.gupta 21
import com.mongodb.MongoConnectionPoolMXBean;
22165 amit.gupta 22
import com.spice.profitmandi.dao.repository.dtr.Mongo;
23
 
21625 kshitij.so 24
@SuppressWarnings("deprecation")
21555 kshitij.so 25
@Configuration
26
@ComponentScan("com.spice.profitmandi.*")
27
public class AppConfig {
28
 
21625 kshitij.so 29
	private static final String VELOCITY_PATH_PREFIX="/WEB-INF/views/ftl/";
30
	private static final String VELOCITY_PATH_SUFFIX=".vm";
21555 kshitij.so 31
	private static final String MESSAGE_PATH_SOURCE_NAME="classpath:message";
32
	private static final Logger LOGGER=LoggerFactory.getLogger(AppConfig.class);
33
	private static Resource resource;
22171 amit.gupta 34
 
21625 kshitij.so 35
 
22171 amit.gupta 36
 
37
	@Value("${mongo.host}")
38
	private String mongoHost;
39
 
40
	@Value("${content.mongo.host}")
41
	private String contentMongoHost;
42
 
21555 kshitij.so 43
	public static Resource getResource() {
44
		return resource;
45
	}
46
 
47
	public void setResource(Resource resource) {
48
		AppConfig.resource = resource;
49
	}
21625 kshitij.so 50
 
51
	@Bean
52
	public ViewResolver viewResolver()
53
	{
54
		VelocityLayoutViewResolver bean = new VelocityLayoutViewResolver();
55
		bean.setCache(false);
56
		bean.setPrefix("");
57
		bean.setSuffix(VELOCITY_PATH_SUFFIX);
22108 amit.gupta 58
		bean.setRequestContextAttribute("rc");
21625 kshitij.so 59
		return bean;
21555 kshitij.so 60
	}
21625 kshitij.so 61
 
21555 kshitij.so 62
	@Bean
21625 kshitij.so 63
	public VelocityConfigurer velocityConfig() {
64
		VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
65
		velocityConfigurer.setResourceLoaderPath(VELOCITY_PATH_PREFIX);
66
		return velocityConfigurer;
21555 kshitij.so 67
	}
68
 
69
	@Bean(name="messageSource")
70
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
71
		LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
72
		ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
73
		messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
74
		return messageSource;
75
	}
76
 
77
	@Bean(name="multipartResolver")
78
	public CommonsMultipartResolver getCommonsMultipartResolver() {
79
		LOGGER.info("creating common multipart resolver bean");
80
		return new CommonsMultipartResolver();
81
	}
82
 
83
	@Bean
84
	public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
85
		String activeProfile;
86
 
87
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
21625 kshitij.so 88
 
21555 kshitij.so 89
		Properties properties = new Properties();
90
		try {
91
			properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
92
		} catch (IOException e) {
93
			LOGGER.error("Error in reading env property file.Adding default property"+e);
94
			properties.put("profile", "dev");
95
		}
96
		activeProfile = (String) properties.get("profile");
97
 
21625 kshitij.so 98
 
21555 kshitij.so 99
		if ("prod".equals(activeProfile)) {
100
			resource = new ClassPathResource("/META-INF/prod.properties");
101
		} else if ("staging".equals(activeProfile)) {
102
			resource = new ClassPathResource("/META-INF/staging.properties");
103
		} else {
104
			resource = new ClassPathResource("/META-INF/dev.properties");
105
		}
106
 
107
		propertySourcesPlaceholderConfigurer.setLocation(resource);
108
 
109
		return propertySourcesPlaceholderConfigurer;
110
	}
22165 amit.gupta 111
 
112
	@Bean
113
    public Mongo mongoClient() {
22171 amit.gupta 114
        return new Mongo(mongoHost, contentMongoHost);
22165 amit.gupta 115
    }
21625 kshitij.so 116
 
21555 kshitij.so 117
}