| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.config;
|
1 |
package com.spice.profitmandi.web.config;
|
| 2 |
|
2 |
|
| 3 |
import java.io.IOException;
|
3 |
import java.io.IOException;
|
| - |
|
4 |
import java.time.LocalDateTime;
|
| 4 |
import java.util.Properties;
|
5 |
import java.util.Properties;
|
| 5 |
|
6 |
|
| 6 |
import org.slf4j.Logger;
|
7 |
import org.slf4j.Logger;
|
| 7 |
import org.slf4j.LoggerFactory;
|
8 |
import org.slf4j.LoggerFactory;
|
| 8 |
import org.springframework.context.annotation.Bean;
|
9 |
import org.springframework.context.annotation.Bean;
|
| Line 13... |
Line 14... |
| 13 |
import org.springframework.core.io.ClassPathResource;
|
14 |
import org.springframework.core.io.ClassPathResource;
|
| 14 |
import org.springframework.core.io.Resource;
|
15 |
import org.springframework.core.io.Resource;
|
| 15 |
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
16 |
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
| 16 |
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
17 |
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
| 17 |
|
18 |
|
| - |
|
19 |
import com.google.gson.Gson;
|
| - |
|
20 |
import com.google.gson.GsonBuilder;
|
| - |
|
21 |
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
|
| - |
|
22 |
|
| 18 |
@Configuration
|
23 |
@Configuration
|
| 19 |
@ComponentScan("com.spice.profitmandi.*")
|
24 |
@ComponentScan("com.spice.profitmandi.*")
|
| 20 |
public class AppConfig {
|
25 |
public class AppConfig {
|
| 21 |
|
26 |
|
| 22 |
//private static final String FTL_PATH_PREFIX="/WEB-INF/views/ftl/";
|
27 |
// private static final String FTL_PATH_PREFIX="/WEB-INF/views/ftl/";
|
| 23 |
//private static final String FTL_PATH_SUFFIX=".ftl";
|
28 |
// private static final String FTL_PATH_SUFFIX=".ftl";
|
| 24 |
private static final String HTML_PATH_PREFIX="/WEB-INF/views/";
|
29 |
private static final String HTML_PATH_PREFIX = "/WEB-INF/views/";
|
| 25 |
private static final String HTML_PATH_SUFFIX=".jsp";
|
30 |
private static final String HTML_PATH_SUFFIX = ".jsp";
|
| 26 |
private static final String MESSAGE_PATH_SOURCE_NAME="classpath:message";
|
31 |
private static final String MESSAGE_PATH_SOURCE_NAME = "classpath:message";
|
| 27 |
private static final Logger LOGGER=LoggerFactory.getLogger(AppConfig.class);
|
32 |
private static final Logger LOGGER = LoggerFactory.getLogger(AppConfig.class);
|
| 28 |
private static Resource resource;
|
33 |
private static Resource resource;
|
| 29 |
|
34 |
|
| 30 |
public static Resource getResource() {
|
35 |
public static Resource getResource() {
|
| 31 |
return resource;
|
36 |
return resource;
|
| 32 |
}
|
37 |
}
|
| 33 |
|
38 |
|
| 34 |
public void setResource(Resource resource) {
|
39 |
public void setResource(Resource resource) {
|
| 35 |
AppConfig.resource = resource;
|
40 |
AppConfig.resource = resource;
|
| 36 |
}
|
41 |
}
|
| 37 |
|
42 |
|
| 38 |
/*@Bean
|
43 |
/*
|
| 39 |
public FreeMarkerConfigurer freemarkerConfig() {
|
44 |
* @Bean public FreeMarkerConfigurer freemarkerConfig() { FreeMarkerConfigurer
|
| 40 |
FreeMarkerConfigurer freeMarkerConfigurer = new FreeMarkerConfigurer();
|
45 |
* freeMarkerConfigurer = new FreeMarkerConfigurer();
|
| 41 |
freeMarkerConfigurer.setTemplateLoaderPath(PATH_PREFIX);
|
46 |
* freeMarkerConfigurer.setTemplateLoaderPath(PATH_PREFIX); return
|
| 42 |
return freeMarkerConfigurer;
|
47 |
* freeMarkerConfigurer; }
|
| 43 |
}
|
48 |
*
|
| 44 |
|
- |
|
| 45 |
@Bean
|
- |
|
| 46 |
public FreeMarkerViewResolver freemarkerViewResolver() {
|
49 |
* @Bean public FreeMarkerViewResolver freemarkerViewResolver() {
|
| 47 |
FreeMarkerViewResolver resolver = new FreeMarkerViewResolver();
|
50 |
* FreeMarkerViewResolver resolver = new FreeMarkerViewResolver();
|
| 48 |
resolver.setCache(false);
|
51 |
* resolver.setCache(false); resolver.setPrefix("");
|
| 49 |
resolver.setPrefix("");
|
- |
|
| 50 |
resolver.setSuffix(PATH_SUFFIX);
|
52 |
* resolver.setSuffix(PATH_SUFFIX); return resolver; }
|
| 51 |
return resolver;
|
- |
|
| 52 |
}*/
|
53 |
*/
|
| 53 |
|
54 |
|
| 54 |
@Bean(name = "viewResolver")
|
55 |
@Bean(name = "viewResolver")
|
| 55 |
public InternalResourceViewResolver getViewResolver() {
|
56 |
public InternalResourceViewResolver getViewResolver() {
|
| - |
|
57 |
LOGGER.debug(
|
| 56 |
LOGGER.debug("creating view resolver bean with prefix : "+HTML_PATH_PREFIX+" and suffix : "+HTML_PATH_SUFFIX);
|
58 |
"creating view resolver bean with prefix : " + HTML_PATH_PREFIX + " and suffix : " + HTML_PATH_SUFFIX);
|
| 57 |
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
|
59 |
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
|
| 58 |
viewResolver.setPrefix(HTML_PATH_PREFIX);
|
60 |
viewResolver.setPrefix(HTML_PATH_PREFIX);
|
| 59 |
viewResolver.setSuffix(HTML_PATH_SUFFIX);
|
61 |
viewResolver.setSuffix(HTML_PATH_SUFFIX);
|
| 60 |
return viewResolver;
|
62 |
return viewResolver;
|
| 61 |
}
|
63 |
}
|
| 62 |
|
64 |
|
| 63 |
@Bean(name="messageSource")
|
65 |
@Bean(name = "messageSource")
|
| 64 |
public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
|
66 |
public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
|
| 65 |
LOGGER.debug("creating messageSource bean with message path source name : "+MESSAGE_PATH_SOURCE_NAME);
|
67 |
LOGGER.debug("creating messageSource bean with message path source name : " + MESSAGE_PATH_SOURCE_NAME);
|
| 66 |
ReloadableResourceBundleMessageSource messageSource=new ReloadableResourceBundleMessageSource();
|
68 |
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
|
| 67 |
messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
|
69 |
messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
|
| 68 |
return messageSource;
|
70 |
return messageSource;
|
| 69 |
}
|
71 |
}
|
| 70 |
|
72 |
|
| 71 |
@Bean(name="multipartResolver")
|
73 |
@Bean(name = "multipartResolver")
|
| 72 |
public CommonsMultipartResolver getCommonsMultipartResolver() {
|
74 |
public CommonsMultipartResolver getCommonsMultipartResolver() {
|
| 73 |
LOGGER.info("creating common multipart resolver bean");
|
75 |
LOGGER.info("creating common multipart resolver bean");
|
| 74 |
return new CommonsMultipartResolver();
|
76 |
return new CommonsMultipartResolver();
|
| 75 |
}
|
77 |
}
|
| 76 |
|
78 |
|
| 77 |
@Bean
|
79 |
@Bean
|
| 78 |
public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
|
80 |
public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
|
| 79 |
String activeProfile;
|
81 |
String activeProfile;
|
| 80 |
|
82 |
|
| 81 |
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
|
83 |
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
|
| 82 |
|
84 |
|
| 83 |
Properties properties = new Properties();
|
85 |
Properties properties = new Properties();
|
| 84 |
try {
|
86 |
try {
|
| 85 |
properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
|
87 |
properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
|
| 86 |
} catch (IOException e) {
|
88 |
} catch (IOException e) {
|
| 87 |
LOGGER.error("Error in reading env property file.Adding default property"+e);
|
89 |
LOGGER.error("Error in reading env property file.Adding default property" + e);
|
| 88 |
properties.put("profile", "dev");
|
90 |
properties.put("profile", "dev");
|
| 89 |
}
|
91 |
}
|
| 90 |
activeProfile = (String) properties.get("profile");
|
92 |
activeProfile = (String) properties.get("profile");
|
| 91 |
|
- |
|
| 92 |
|
93 |
|
| 93 |
if ("prod".equals(activeProfile)) {
|
94 |
if ("prod".equals(activeProfile)) {
|
| 94 |
resource = new ClassPathResource("/META-INF/prod.properties");
|
95 |
resource = new ClassPathResource("/META-INF/prod.properties");
|
| 95 |
} else if ("staging".equals(activeProfile)) {
|
96 |
} else if ("staging".equals(activeProfile)) {
|
| 96 |
resource = new ClassPathResource("/META-INF/staging.properties");
|
97 |
resource = new ClassPathResource("/META-INF/staging.properties");
|
| Line 100... |
Line 101... |
| 100 |
|
101 |
|
| 101 |
propertySourcesPlaceholderConfigurer.setLocation(resource);
|
102 |
propertySourcesPlaceholderConfigurer.setLocation(resource);
|
| 102 |
|
103 |
|
| 103 |
return propertySourcesPlaceholderConfigurer;
|
104 |
return propertySourcesPlaceholderConfigurer;
|
| 104 |
}
|
105 |
}
|
| - |
|
106 |
|
| - |
|
107 |
@Bean(name = "gson")
|
| - |
|
108 |
public Gson gson() {
|
| - |
|
109 |
|
| - |
|
110 |
Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
|
| - |
|
111 |
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter()).create();
|
| - |
|
112 |
|
| - |
|
113 |
return gson;
|
| - |
|
114 |
|
| 105 |
|
115 |
}
|
| - |
|
116 |
|
| 106 |
}
|
117 |
}
|
| 107 |
|
118 |
|