Subversion Repositories SmartDukaan

Rev

Rev 23568 | Rev 23869 | 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;
23784 ashik.ali 4
 
21555 kshitij.so 5
import java.util.Properties;
6
 
23568 govind 7
import org.apache.logging.log4j.Logger;
8
import org.apache.logging.log4j.LogManager;
21555 kshitij.so 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";
23568 govind 29
	private static final Logger LOGGER=LogManager.getLogger(AppConfig.class);
21555 kshitij.so 30
	private static Resource resource;
22171 amit.gupta 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.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
}