Subversion Repositories SmartDukaan

Rev

Rev 22171 | Rev 22244 | 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
 
21555 kshitij.so 35
	public static Resource getResource() {
36
		return resource;
37
	}
38
 
39
	public void setResource(Resource resource) {
40
		AppConfig.resource = resource;
41
	}
21625 kshitij.so 42
 
43
	@Bean
44
	public ViewResolver viewResolver()
45
	{
46
		VelocityLayoutViewResolver bean = new VelocityLayoutViewResolver();
47
		bean.setCache(false);
48
		bean.setPrefix("");
49
		bean.setSuffix(VELOCITY_PATH_SUFFIX);
22108 amit.gupta 50
		bean.setRequestContextAttribute("rc");
21625 kshitij.so 51
		return bean;
21555 kshitij.so 52
	}
21625 kshitij.so 53
 
21555 kshitij.so 54
	@Bean
21625 kshitij.so 55
	public VelocityConfigurer velocityConfig() {
56
		VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
57
		velocityConfigurer.setResourceLoaderPath(VELOCITY_PATH_PREFIX);
58
		return velocityConfigurer;
21555 kshitij.so 59
	}
60
 
61
	@Bean(name="messageSource")
62
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
63
		LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
64
		ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
65
		messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
66
		return messageSource;
67
	}
68
 
69
	@Bean(name="multipartResolver")
70
	public CommonsMultipartResolver getCommonsMultipartResolver() {
71
		LOGGER.info("creating common multipart resolver bean");
72
		return new CommonsMultipartResolver();
73
	}
74
 
75
	@Bean
76
	public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
77
		String activeProfile;
78
 
79
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
21625 kshitij.so 80
 
21555 kshitij.so 81
		Properties properties = new Properties();
82
		try {
83
			properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
84
		} catch (IOException e) {
85
			LOGGER.error("Error in reading env property file.Adding default property"+e);
86
			properties.put("profile", "dev");
87
		}
88
		activeProfile = (String) properties.get("profile");
89
 
21625 kshitij.so 90
 
21555 kshitij.so 91
		if ("prod".equals(activeProfile)) {
92
			resource = new ClassPathResource("/META-INF/prod.properties");
93
		} else if ("staging".equals(activeProfile)) {
94
			resource = new ClassPathResource("/META-INF/staging.properties");
95
		} else {
96
			resource = new ClassPathResource("/META-INF/dev.properties");
97
		}
98
 
99
		propertySourcesPlaceholderConfigurer.setLocation(resource);
100
 
101
		return propertySourcesPlaceholderConfigurer;
102
	}
21625 kshitij.so 103
 
21555 kshitij.so 104
}