Subversion Repositories SmartDukaan

Rev

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