Subversion Repositories SmartDukaan

Rev

Rev 22108 | Rev 22165 | 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;
22113 ashik.ali 4
 
21555 kshitij.so 5
import java.util.Properties;
6
 
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;
12
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
13
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
14
import org.springframework.core.io.ClassPathResource;
15
import org.springframework.core.io.Resource;
16
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
21625 kshitij.so 17
import org.springframework.web.servlet.ViewResolver;
18
import org.springframework.web.servlet.view.velocity.VelocityConfigurer;
19
import org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver;
21555 kshitij.so 20
 
21625 kshitij.so 21
@SuppressWarnings("deprecation")
21555 kshitij.so 22
@Configuration
23
@ComponentScan("com.spice.profitmandi.*")
24
public class AppConfig {
25
 
21625 kshitij.so 26
	private static final String VELOCITY_PATH_PREFIX="/WEB-INF/views/ftl/";
27
	private static final String VELOCITY_PATH_SUFFIX=".vm";
21555 kshitij.so 28
	private static final String MESSAGE_PATH_SOURCE_NAME="classpath:message";
29
	private static final Logger LOGGER=LoggerFactory.getLogger(AppConfig.class);
30
	private static Resource resource;
21625 kshitij.so 31
 
21555 kshitij.so 32
	public static Resource getResource() {
33
		return resource;
34
	}
35
 
36
	public void setResource(Resource resource) {
37
		AppConfig.resource = resource;
38
	}
21625 kshitij.so 39
 
40
	@Bean
41
	public ViewResolver viewResolver()
42
	{
43
		VelocityLayoutViewResolver bean = new VelocityLayoutViewResolver();
44
		bean.setCache(false);
45
		bean.setPrefix("");
46
		bean.setSuffix(VELOCITY_PATH_SUFFIX);
22108 amit.gupta 47
		bean.setRequestContextAttribute("rc");
21625 kshitij.so 48
		return bean;
21555 kshitij.so 49
	}
21625 kshitij.so 50
 
21555 kshitij.so 51
	@Bean
21625 kshitij.so 52
	public VelocityConfigurer velocityConfig() {
53
		VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
54
		velocityConfigurer.setResourceLoaderPath(VELOCITY_PATH_PREFIX);
55
		return velocityConfigurer;
21555 kshitij.so 56
	}
57
 
58
	@Bean(name="messageSource")
59
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
60
		LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
61
		ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
62
		messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
63
		return messageSource;
64
	}
65
 
66
	@Bean(name="multipartResolver")
67
	public CommonsMultipartResolver getCommonsMultipartResolver() {
68
		LOGGER.info("creating common multipart resolver bean");
69
		return new CommonsMultipartResolver();
70
	}
71
 
72
	@Bean
73
	public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
74
		String activeProfile;
75
 
76
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
21625 kshitij.so 77
 
21555 kshitij.so 78
		Properties properties = new Properties();
79
		try {
80
			properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
81
		} catch (IOException e) {
82
			LOGGER.error("Error in reading env property file.Adding default property"+e);
83
			properties.put("profile", "dev");
84
		}
85
		activeProfile = (String) properties.get("profile");
86
 
21625 kshitij.so 87
 
21555 kshitij.so 88
		if ("prod".equals(activeProfile)) {
89
			resource = new ClassPathResource("/META-INF/prod.properties");
90
		} else if ("staging".equals(activeProfile)) {
91
			resource = new ClassPathResource("/META-INF/staging.properties");
92
		} else {
93
			resource = new ClassPathResource("/META-INF/dev.properties");
94
		}
95
 
96
		propertySourcesPlaceholderConfigurer.setLocation(resource);
97
 
98
		return propertySourcesPlaceholderConfigurer;
99
	}
21625 kshitij.so 100
 
21555 kshitij.so 101
}