Subversion Repositories SmartDukaan

Rev

Rev 22103 | Rev 22113 | 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);
22108 amit.gupta 46
		bean.setRequestContextAttribute("rc");
21625 kshitij.so 47
		return bean;
21555 kshitij.so 48
	}
21625 kshitij.so 49
 
21555 kshitij.so 50
	@Bean
21625 kshitij.so 51
	public VelocityConfigurer velocityConfig() {
52
		VelocityConfigurer velocityConfigurer = new VelocityConfigurer();
53
		velocityConfigurer.setResourceLoaderPath(VELOCITY_PATH_PREFIX);
54
		return velocityConfigurer;
21555 kshitij.so 55
	}
56
 
57
	@Bean(name="messageSource")
58
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
59
		LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
60
		ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
61
		messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
62
		return messageSource;
63
	}
64
 
65
	@Bean(name="multipartResolver")
66
	public CommonsMultipartResolver getCommonsMultipartResolver() {
67
		LOGGER.info("creating common multipart resolver bean");
68
		return new CommonsMultipartResolver();
69
	}
70
 
71
	@Bean
72
	public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
73
		String activeProfile;
74
 
75
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
21625 kshitij.so 76
 
21555 kshitij.so 77
		Properties properties = new Properties();
78
		try {
79
			properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
80
		} catch (IOException e) {
81
			LOGGER.error("Error in reading env property file.Adding default property"+e);
82
			properties.put("profile", "dev");
83
		}
84
		activeProfile = (String) properties.get("profile");
85
 
21625 kshitij.so 86
 
21555 kshitij.so 87
		if ("prod".equals(activeProfile)) {
88
			resource = new ClassPathResource("/META-INF/prod.properties");
89
		} else if ("staging".equals(activeProfile)) {
90
			resource = new ClassPathResource("/META-INF/staging.properties");
91
		} else {
92
			resource = new ClassPathResource("/META-INF/dev.properties");
93
		}
94
 
95
		propertySourcesPlaceholderConfigurer.setLocation(resource);
96
 
97
		return propertySourcesPlaceholderConfigurer;
98
	}
21625 kshitij.so 99
 
21555 kshitij.so 100
}