Subversion Repositories SmartDukaan

Rev

Rev 21304 | Rev 21343 | 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
 
3
import org.slf4j.Logger;
4
 
5
import org.slf4j.LoggerFactory;
6
import org.springframework.context.annotation.Bean;
7
import org.springframework.context.annotation.ComponentScan;
8
import org.springframework.context.annotation.Configuration;
21304 kshitij.so 9
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
21165 ashik.ali 10
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
21304 kshitij.so 11
import org.springframework.core.io.ClassPathResource;
12
import org.springframework.core.io.Resource;
21165 ashik.ali 13
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
14
import org.springframework.web.servlet.view.InternalResourceViewResolver;
15
 
16
@Configuration
17
@ComponentScan("com.spice.profitmandi.*")
18
public class AppConfig {
21304 kshitij.so 19
 
21165 ashik.ali 20
	private static final String PATH_PREFIX="/WEB-INF/views/";
21
	private static final String PATH_SUFFIX=".jsp";
22
	private static final String MESSAGE_PATH_SOURCE_NAME="classpath:message";
23
	private static final Logger LOGGER=LoggerFactory.getLogger(AppConfig.class);
21304 kshitij.so 24
 
21165 ashik.ali 25
	@Bean(name = "viewResolver")
26
	public InternalResourceViewResolver getViewResolver() {
27
		LOGGER.debug("creating view resolver bean with prefix : "+PATH_PREFIX+" and suffix : "+PATH_SUFFIX);
21304 kshitij.so 28
		InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
29
		viewResolver.setPrefix(PATH_PREFIX);
30
		viewResolver.setSuffix(PATH_SUFFIX);
31
		return viewResolver;
21165 ashik.ali 32
	}
21304 kshitij.so 33
 
21165 ashik.ali 34
	@Bean(name="messageSource")
35
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
36
		LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
37
		ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
38
		messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
39
		return messageSource;
40
	}
21304 kshitij.so 41
 
21165 ashik.ali 42
	@Bean(name="multipartResolver")
43
	public CommonsMultipartResolver getCommonsMultipartResolver() {
44
		LOGGER.info("creating common multipart resolver bean");
45
		return new CommonsMultipartResolver();
21304 kshitij.so 46
	}
47
 
48
	@Bean
49
	public static PropertySourcesPlaceholderConfigurer propertyConfigurer() {
50
		Resource resource;
51
		String activeProfile;
52
 
53
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
54
 
55
		activeProfile = System.getProperty("spring.profiles.active");
56
 
57
		if ("prod".equals(activeProfile)) {
58
			resource = new ClassPathResource("/META-INF/prod.properties");
59
		} else if ("staging".equals(activeProfile)) {
21342 kshitij.so 60
			resource = new ClassPathResource("/META-INF/staging.properties");
21304 kshitij.so 61
		} else {
62
			resource = new ClassPathResource("/META-INF/dev.properties");
63
		}
64
 
65
		propertySourcesPlaceholderConfigurer.setLocation(resource);
66
 
67
		return propertySourcesPlaceholderConfigurer;
68
	}
21165 ashik.ali 69
}