Subversion Repositories SmartDukaan

Rev

Rev 22113 | Rev 22171 | 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
 
22165 amit.gupta 20
import com.spice.profitmandi.dao.repository.dtr.Mongo;
21
 
21625 kshitij.so 22
@SuppressWarnings("deprecation")
21555 kshitij.so 23
@Configuration
24
@ComponentScan("com.spice.profitmandi.*")
25
public class AppConfig {
26
 
21625 kshitij.so 27
	private static final String VELOCITY_PATH_PREFIX="/WEB-INF/views/ftl/";
28
	private static final String VELOCITY_PATH_SUFFIX=".vm";
21555 kshitij.so 29
	private static final String MESSAGE_PATH_SOURCE_NAME="classpath:message";
30
	private static final Logger LOGGER=LoggerFactory.getLogger(AppConfig.class);
31
	private static Resource resource;
21625 kshitij.so 32
 
21555 kshitij.so 33
	public static Resource getResource() {
34
		return resource;
35
	}
36
 
37
	public void setResource(Resource resource) {
38
		AppConfig.resource = resource;
39
	}
21625 kshitij.so 40
 
41
	@Bean
42
	public ViewResolver viewResolver()
43
	{
44
		VelocityLayoutViewResolver bean = new VelocityLayoutViewResolver();
45
		bean.setCache(false);
46
		bean.setPrefix("");
47
		bean.setSuffix(VELOCITY_PATH_SUFFIX);
22108 amit.gupta 48
		bean.setRequestContextAttribute("rc");
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
	}
22165 amit.gupta 101
 
102
	@Bean
103
    public Mongo mongoClient() {
104
        return new Mongo();
105
    }
21625 kshitij.so 106
 
21555 kshitij.so 107
}