Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
21165 ashik.ali 1
package com.spice.profitmandi.web.config;
2
 
21343 kshitij.so 3
import java.io.FileInputStream;
4
import java.io.IOException;
5
import java.util.Properties;
6
 
21165 ashik.ali 7
import org.slf4j.Logger;
8
import org.slf4j.LoggerFactory;
9
import org.springframework.context.annotation.Bean;
10
import org.springframework.context.annotation.ComponentScan;
11
import org.springframework.context.annotation.Configuration;
21304 kshitij.so 12
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
21165 ashik.ali 13
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
21304 kshitij.so 14
import org.springframework.core.io.ClassPathResource;
15
import org.springframework.core.io.Resource;
21165 ashik.ali 16
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
17
import org.springframework.web.servlet.view.InternalResourceViewResolver;
18
 
19
@Configuration
20
@ComponentScan("com.spice.profitmandi.*")
21
public class AppConfig {
21304 kshitij.so 22
 
21165 ashik.ali 23
	private static final String PATH_PREFIX="/WEB-INF/views/";
24
	private static final String PATH_SUFFIX=".jsp";
25
	private static final String MESSAGE_PATH_SOURCE_NAME="classpath:message";
26
	private static final Logger LOGGER=LoggerFactory.getLogger(AppConfig.class);
21343 kshitij.so 27
 
21165 ashik.ali 28
	@Bean(name = "viewResolver")
29
	public InternalResourceViewResolver getViewResolver() {
30
		LOGGER.debug("creating view resolver bean with prefix : "+PATH_PREFIX+" and suffix : "+PATH_SUFFIX);
21304 kshitij.so 31
		InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
32
		viewResolver.setPrefix(PATH_PREFIX);
33
		viewResolver.setSuffix(PATH_SUFFIX);
34
		return viewResolver;
21165 ashik.ali 35
	}
21304 kshitij.so 36
 
21165 ashik.ali 37
	@Bean(name="messageSource")
38
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
39
		LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
40
		ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
41
		messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
42
		return messageSource;
43
	}
21304 kshitij.so 44
 
21165 ashik.ali 45
	@Bean(name="multipartResolver")
46
	public CommonsMultipartResolver getCommonsMultipartResolver() {
47
		LOGGER.info("creating common multipart resolver bean");
48
		return new CommonsMultipartResolver();
21304 kshitij.so 49
	}
50
 
51
	@Bean
21343 kshitij.so 52
	public PropertySourcesPlaceholderConfigurer propertyConfigurer() {
21304 kshitij.so 53
		Resource resource;
54
		String activeProfile;
55
 
56
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
21343 kshitij.so 57
 
58
		Properties properties = new Properties();
59
		try {
60
			properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
61
		} catch (IOException e) {
21348 kshitij.so 62
			LOGGER.error("Error in reading env property file.Adding default property"+e);
21343 kshitij.so 63
			properties.put("profile", "dev");
64
		}
65
		activeProfile = (String) properties.get("profile");
66
 
21304 kshitij.so 67
 
68
		if ("prod".equals(activeProfile)) {
69
			resource = new ClassPathResource("/META-INF/prod.properties");
70
		} else if ("staging".equals(activeProfile)) {
21342 kshitij.so 71
			resource = new ClassPathResource("/META-INF/staging.properties");
21304 kshitij.so 72
		} else {
73
			resource = new ClassPathResource("/META-INF/dev.properties");
74
		}
75
 
76
		propertySourcesPlaceholderConfigurer.setLocation(resource);
77
 
78
		return propertySourcesPlaceholderConfigurer;
79
	}
21165 ashik.ali 80
}