Subversion Repositories SmartDukaan

Rev

Rev 21598 | Rev 22103 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21598 Rev 21625
Line 11... Line 11...
11
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
11
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
12
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
12
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
13
import org.springframework.core.io.ClassPathResource;
13
import org.springframework.core.io.ClassPathResource;
14
import org.springframework.core.io.Resource;
14
import org.springframework.core.io.Resource;
15
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
15
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
-
 
16
import org.springframework.web.servlet.ViewResolver;
16
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
17
import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
17
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;
18
import org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver;
18
 
19
 
-
 
20
@SuppressWarnings("deprecation")
19
@Configuration
21
@Configuration
20
@ComponentScan("com.spice.profitmandi.*")
22
@ComponentScan("com.spice.profitmandi.*")
21
public class AppConfig {
23
public class AppConfig {
22
 
24
 
23
	private static final String FTL_PATH_PREFIX="/WEB-INF/views/ftl/";
25
	private static final String VELOCITY_PATH_PREFIX="/WEB-INF/views/ftl/";
24
	private static final String FTL_PATH_SUFFIX=".ftl";
26
	private static final String VELOCITY_PATH_SUFFIX=".vm";
25
	private static final String MESSAGE_PATH_SOURCE_NAME="classpath:message";
27
	private static final String MESSAGE_PATH_SOURCE_NAME="classpath:message";
26
	private static final Logger LOGGER=LoggerFactory.getLogger(AppConfig.class);
28
	private static final Logger LOGGER=LoggerFactory.getLogger(AppConfig.class);
27
	private static Resource resource;
29
	private static Resource resource;
28
	
30
 
29
	public static Resource getResource() {
31
	public static Resource getResource() {
30
		return resource;
32
		return resource;
31
	}
33
	}
32
 
34
 
33
	public void setResource(Resource resource) {
35
	public void setResource(Resource resource) {
34
		AppConfig.resource = resource;
36
		AppConfig.resource = resource;
35
	}
37
	}
36
	
38
 
37
	@Bean 
39
	@Bean
38
	public FreeMarkerConfigurer freemarkerConfig() { 
40
	public ViewResolver viewResolver()
-
 
41
	{
39
	    FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer(); 
42
		VelocityLayoutViewResolver bean = new VelocityLayoutViewResolver();
-
 
43
		bean.setCache(false);
-
 
44
		bean.setPrefix("");
40
	    freeMarkerConfigurer.setTemplateLoaderPath(FTL_PATH_PREFIX);
45
		bean.setSuffix(VELOCITY_PATH_SUFFIX);
41
	    return freeMarkerConfigurer; 
46
		return bean;
42
	}
47
	}
43
	
48
 
44
	@Bean
49
	@Bean
45
	public FreeMarkerViewResolver freemarkerViewResolver() { 
50
	public VelocityConfigurer velocityConfig() {
46
	    FreeMarkerViewResolver resolver = new FreeMarkerViewResolver(); 
51
		VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
47
	    resolver.setCache(false); 
-
 
48
	    resolver.setPrefix(""); 
-
 
49
	    resolver.setSuffix(FTL_PATH_SUFFIX); 
52
		velocityConfigurer.setResourceLoaderPath(VELOCITY_PATH_PREFIX);
50
	    return resolver; 
53
		return velocityConfigurer;
51
	}
54
	}
52
	
-
 
53
	 
-
 
54
//	@Bean(name = "viewResolver")
-
 
55
//	public InternalResourceViewResolver getViewResolver() {
-
 
56
//		LOGGER.debug("creating view resolver bean with prefix : "+HTML_PATH_PREFIX+" and suffix : "+HTML_PATH_SUFFIX);
-
 
57
//		InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
-
 
58
//		viewResolver.setPrefix(HTML_PATH_PREFIX);
-
 
59
//		viewResolver.setSuffix(HTML_PATH_SUFFIX);
-
 
60
//		return viewResolver;
-
 
61
//	}
-
 
62
 
55
 
63
	@Bean(name="messageSource")
56
	@Bean(name="messageSource")
64
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
57
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
65
		LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
58
		LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
66
		ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
59
		ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
Line 77... Line 70...
77
	@Bean
70
	@Bean
78
	public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
71
	public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
79
		String activeProfile;
72
		String activeProfile;
80
 
73
 
81
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
74
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
82
		
75
 
83
		Properties properties = new Properties();
76
		Properties properties = new Properties();
84
		try {
77
		try {
85
			properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
78
			properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
86
		} catch (IOException e) {
79
		} catch (IOException e) {
87
			LOGGER.error("Error in reading env property file.Adding default property"+e);
80
			LOGGER.error("Error in reading env property file.Adding default property"+e);
88
			properties.put("profile", "dev");
81
			properties.put("profile", "dev");
89
		}
82
		}
90
		activeProfile = (String) properties.get("profile");
83
		activeProfile = (String) properties.get("profile");
91
		
84
 
92
 
85
 
93
		if ("prod".equals(activeProfile)) {
86
		if ("prod".equals(activeProfile)) {
94
			resource = new ClassPathResource("/META-INF/prod.properties");
87
			resource = new ClassPathResource("/META-INF/prod.properties");
95
		} else if ("staging".equals(activeProfile)) {
88
		} else if ("staging".equals(activeProfile)) {
96
			resource = new ClassPathResource("/META-INF/staging.properties");
89
			resource = new ClassPathResource("/META-INF/staging.properties");
Line 100... Line 93...
100
 
93
 
101
		propertySourcesPlaceholderConfigurer.setLocation(resource);
94
		propertySourcesPlaceholderConfigurer.setLocation(resource);
102
 
95
 
103
		return propertySourcesPlaceholderConfigurer;
96
		return propertySourcesPlaceholderConfigurer;
104
	}
97
	}
105
	
98
 
106
}
99
}
107
100