Subversion Repositories SmartDukaan

Rev

Rev 21561 | Rev 21625 | 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 MESSAGE_PATH_SOURCE_NAME="classpath:message";
26
	private static final Logger LOGGER=LoggerFactory.getLogger(AppConfig.class);
27
	private static Resource resource;
28
 
29
	public static Resource getResource() {
30
		return resource;
31
	}
32
 
33
	public void setResource(Resource resource) {
34
		AppConfig.resource = resource;
35
	}
36
 
37
	@Bean 
38
	public FreeMarkerConfigurer freemarkerConfig() { 
39
	    FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer(); 
40
	    freeMarkerConfigurer.setTemplateLoaderPath(FTL_PATH_PREFIX);
41
	    return freeMarkerConfigurer; 
42
	}
43
 
44
	@Bean
45
	public FreeMarkerViewResolver freemarkerViewResolver() { 
46
	    FreeMarkerViewResolver resolver = new FreeMarkerViewResolver(); 
47
	    resolver.setCache(false); 
48
	    resolver.setPrefix(""); 
49
	    resolver.setSuffix(FTL_PATH_SUFFIX); 
50
	    return resolver; 
51
	}
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
}