Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
21749 ashik.ali 1
package com.spice.profitmandi.web.config;
21541 ashik.ali 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.InternalResourceViewResolver;
17
 
18
@Configuration
19
@ComponentScan("com.spice.profitmandi.*")
20
public class AppConfig {
21
 
21749 ashik.ali 22
	//private static final String FTL_PATH_PREFIX="/WEB-INF/views/ftl/";
23
	//private static final String FTL_PATH_SUFFIX=".ftl";
21541 ashik.ali 24
	private static final String HTML_PATH_PREFIX="/WEB-INF/views/";
25
	private static final String HTML_PATH_SUFFIX=".jsp";
26
	private static final String MESSAGE_PATH_SOURCE_NAME="classpath:message";
27
	private static final Logger LOGGER=LoggerFactory.getLogger(AppConfig.class);
28
	private static Resource resource;
29
 
30
	public static Resource getResource() {
31
		return resource;
32
	}
33
 
34
	public void setResource(Resource resource) {
35
		AppConfig.resource = resource;
36
	}
37
 
38
	/*@Bean 
39
	public FreeMarkerConfigurer freemarkerConfig() { 
40
	    FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer(); 
41
	    freeMarkerConfigurer.setTemplateLoaderPath(PATH_PREFIX);
42
	    return freeMarkerConfigurer; 
43
	}
44
 
45
	@Bean
46
	public FreeMarkerViewResolver freemarkerViewResolver() { 
47
	    FreeMarkerViewResolver resolver = new FreeMarkerViewResolver(); 
48
	    resolver.setCache(false); 
49
	    resolver.setPrefix(""); 
50
	    resolver.setSuffix(PATH_SUFFIX); 
51
	    return resolver; 
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
 
63
	@Bean(name="messageSource")
64
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
65
		LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
66
		ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
67
		messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
68
		return messageSource;
69
	}
70
 
71
	@Bean(name="multipartResolver")
72
	public CommonsMultipartResolver getCommonsMultipartResolver() {
73
		LOGGER.info("creating common multipart resolver bean");
74
		return new CommonsMultipartResolver();
75
	}
76
 
77
	@Bean
78
	public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
79
		String activeProfile;
80
 
81
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
82
 
83
		Properties properties = new Properties();
84
		try {
85
			properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
86
		} catch (IOException e) {
87
			LOGGER.error("Error in reading env property file.Adding default property"+e);
88
			properties.put("profile", "dev");
89
		}
90
		activeProfile = (String) properties.get("profile");
91
 
92
 
93
		if ("prod".equals(activeProfile)) {
94
			resource = new ClassPathResource("/META-INF/prod.properties");
95
		} else if ("staging".equals(activeProfile)) {
96
			resource = new ClassPathResource("/META-INF/staging.properties");
97
		} else {
98
			resource = new ClassPathResource("/META-INF/dev.properties");
99
		}
100
 
101
		propertySourcesPlaceholderConfigurer.setLocation(resource);
102
 
103
		return propertySourcesPlaceholderConfigurer;
104
	}
105
 
106
}