| 21165 |
ashik.ali |
1 |
package com.spice.profitmandi.web.config;
|
|
|
2 |
|
| 21343 |
kshitij.so |
3 |
import java.io.IOException;
|
|
|
4 |
import java.util.Properties;
|
|
|
5 |
|
| 21165 |
ashik.ali |
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;
|
| 21304 |
kshitij.so |
11 |
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
| 21165 |
ashik.ali |
12 |
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
|
| 21304 |
kshitij.so |
13 |
import org.springframework.core.io.ClassPathResource;
|
|
|
14 |
import org.springframework.core.io.Resource;
|
| 21165 |
ashik.ali |
15 |
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
|
|
16 |
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
|
|
17 |
|
|
|
18 |
@Configuration
|
|
|
19 |
@ComponentScan("com.spice.profitmandi.*")
|
|
|
20 |
public class AppConfig {
|
| 21304 |
kshitij.so |
21 |
|
| 21165 |
ashik.ali |
22 |
private static final String PATH_PREFIX="/WEB-INF/views/";
|
|
|
23 |
private static final String PATH_SUFFIX=".jsp";
|
|
|
24 |
private static final String MESSAGE_PATH_SOURCE_NAME="classpath:message";
|
|
|
25 |
private static final Logger LOGGER=LoggerFactory.getLogger(AppConfig.class);
|
| 21362 |
kshitij.so |
26 |
private static Resource resource;
|
| 21343 |
kshitij.so |
27 |
|
| 21362 |
kshitij.so |
28 |
public static Resource getResource() {
|
|
|
29 |
return resource;
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
public void setResource(Resource resource) {
|
|
|
33 |
AppConfig.resource = resource;
|
|
|
34 |
}
|
|
|
35 |
|
| 21165 |
ashik.ali |
36 |
@Bean(name = "viewResolver")
|
|
|
37 |
public InternalResourceViewResolver getViewResolver() {
|
|
|
38 |
LOGGER.debug("creating view resolver bean with prefix : "+PATH_PREFIX+" and suffix : "+PATH_SUFFIX);
|
| 21304 |
kshitij.so |
39 |
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
|
|
|
40 |
viewResolver.setPrefix(PATH_PREFIX);
|
|
|
41 |
viewResolver.setSuffix(PATH_SUFFIX);
|
|
|
42 |
return viewResolver;
|
| 21165 |
ashik.ali |
43 |
}
|
| 21304 |
kshitij.so |
44 |
|
| 21165 |
ashik.ali |
45 |
@Bean(name="messageSource")
|
|
|
46 |
public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
|
|
|
47 |
LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
|
|
|
48 |
ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
|
|
|
49 |
messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
|
|
|
50 |
return messageSource;
|
|
|
51 |
}
|
| 21304 |
kshitij.so |
52 |
|
| 21165 |
ashik.ali |
53 |
@Bean(name="multipartResolver")
|
|
|
54 |
public CommonsMultipartResolver getCommonsMultipartResolver() {
|
|
|
55 |
LOGGER.info("creating common multipart resolver bean");
|
|
|
56 |
return new CommonsMultipartResolver();
|
| 21304 |
kshitij.so |
57 |
}
|
|
|
58 |
|
|
|
59 |
@Bean
|
| 21643 |
ashik.ali |
60 |
public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
|
| 21304 |
kshitij.so |
61 |
String activeProfile;
|
|
|
62 |
|
|
|
63 |
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
|
| 21343 |
kshitij.so |
64 |
|
|
|
65 |
Properties properties = new Properties();
|
|
|
66 |
try {
|
|
|
67 |
properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
|
|
|
68 |
} catch (IOException e) {
|
| 21348 |
kshitij.so |
69 |
LOGGER.error("Error in reading env property file.Adding default property"+e);
|
| 21343 |
kshitij.so |
70 |
properties.put("profile", "dev");
|
|
|
71 |
}
|
|
|
72 |
activeProfile = (String) properties.get("profile");
|
|
|
73 |
|
| 21304 |
kshitij.so |
74 |
|
|
|
75 |
if ("prod".equals(activeProfile)) {
|
|
|
76 |
resource = new ClassPathResource("/META-INF/prod.properties");
|
|
|
77 |
} else if ("staging".equals(activeProfile)) {
|
| 21342 |
kshitij.so |
78 |
resource = new ClassPathResource("/META-INF/staging.properties");
|
| 21304 |
kshitij.so |
79 |
} else {
|
|
|
80 |
resource = new ClassPathResource("/META-INF/dev.properties");
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
propertySourcesPlaceholderConfigurer.setLocation(resource);
|
|
|
84 |
|
|
|
85 |
return propertySourcesPlaceholderConfigurer;
|
|
|
86 |
}
|
| 21362 |
kshitij.so |
87 |
|
| 21165 |
ashik.ali |
88 |
}
|