Subversion Repositories SmartDukaan

Rev

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