Subversion Repositories SmartDukaan

Rev

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