Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
23295 ashik.ali 1
package com.spice.profitmandi.web.config;
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.scheduling.annotation.EnableScheduling;
16
 
17
@Configuration
18
@ComponentScan("com.spice.profitmandi.*")
19
@EnableScheduling
20
 
21
public class AppConfig {
22
 
23
	private static final String MESSAGE_PATH_SOURCE_NAME="classpath:message";
24
	private static final Logger LOGGER=LoggerFactory.getLogger(AppConfig.class);
25
	private static Resource resource;
26
 
27
	public static Resource getResource() {
28
		return resource;
29
	}
30
 
31
	public void setResource(Resource resource) {
32
		AppConfig.resource = resource;
33
	}
34
 
35
 
36
 
37
	@Bean(name="messageSource")
38
	public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
39
		LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
40
		ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
41
		messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
42
		return messageSource;
43
	}
44
 
45
	@Bean
46
	public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
47
		String activeProfile;
48
 
49
		PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer =  new PropertySourcesPlaceholderConfigurer();
50
 
51
		Properties properties = new Properties();
52
		try {
53
			properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
54
		} catch (IOException e) {
55
			LOGGER.error("Error in reading env property file.Adding default property"+e);
56
			properties.put("profile", "dev");
57
		}
58
		activeProfile = (String) properties.get("profile");
59
 
60
 
61
		if ("prod".equals(activeProfile)) {
62
			resource = new ClassPathResource("/META-INF/prod.properties");
63
		} else if ("staging".equals(activeProfile)) {
64
			resource = new ClassPathResource("/META-INF/staging.properties");
65
		} else {
66
			resource = new ClassPathResource("/META-INF/dev.properties");
67
		}
68
 
69
		propertySourcesPlaceholderConfigurer.setLocation(resource);
70
 
71
		return propertySourcesPlaceholderConfigurer;
72
	}
73
 
74
 
75
}