Subversion Repositories SmartDukaan

Rev

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