| 24472 |
amit.gupta |
1 |
|
| 21165 |
ashik.ali |
2 |
package com.spice.profitmandi.web.config;
|
|
|
3 |
|
| 21343 |
kshitij.so |
4 |
import java.io.IOException;
|
| 25300 |
tejbeer |
5 |
import java.time.LocalDateTime;
|
| 21343 |
kshitij.so |
6 |
import java.util.Properties;
|
|
|
7 |
|
| 24472 |
amit.gupta |
8 |
import org.apache.logging.log4j.LogManager;
|
| 23568 |
govind |
9 |
import org.apache.logging.log4j.Logger;
|
| 21165 |
ashik.ali |
10 |
import org.springframework.context.annotation.Bean;
|
|
|
11 |
import org.springframework.context.annotation.ComponentScan;
|
|
|
12 |
import org.springframework.context.annotation.Configuration;
|
| 21304 |
kshitij.so |
13 |
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
|
| 21165 |
ashik.ali |
14 |
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
|
| 21304 |
kshitij.so |
15 |
import org.springframework.core.io.ClassPathResource;
|
|
|
16 |
import org.springframework.core.io.Resource;
|
| 22398 |
amit.gupta |
17 |
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
18 |
import org.springframework.mail.javamail.JavaMailSenderImpl;
|
| 21165 |
ashik.ali |
19 |
import org.springframework.web.multipart.commons.CommonsMultipartResolver;
|
|
|
20 |
import org.springframework.web.servlet.view.InternalResourceViewResolver;
|
|
|
21 |
|
| 25300 |
tejbeer |
22 |
import com.google.gson.Gson;
|
|
|
23 |
import com.google.gson.GsonBuilder;
|
|
|
24 |
import com.spice.profitmandi.dao.convertor.LocalDateTimeJsonConverter;
|
|
|
25 |
|
| 21165 |
ashik.ali |
26 |
@Configuration
|
|
|
27 |
@ComponentScan("com.spice.profitmandi.*")
|
|
|
28 |
public class AppConfig {
|
| 21304 |
kshitij.so |
29 |
|
| 25300 |
tejbeer |
30 |
private static final String PATH_PREFIX = "/WEB-INF/views/";
|
|
|
31 |
private static final String PATH_SUFFIX = ".jsp";
|
|
|
32 |
private static final String MESSAGE_PATH_SOURCE_NAME = "classpath:message";
|
|
|
33 |
private static final Logger LOGGER = LogManager.getLogger(AppConfig.class);
|
| 21362 |
kshitij.so |
34 |
private static Resource resource;
|
| 25300 |
tejbeer |
35 |
|
| 21362 |
kshitij.so |
36 |
public static Resource getResource() {
|
|
|
37 |
return resource;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
public void setResource(Resource resource) {
|
|
|
41 |
AppConfig.resource = resource;
|
|
|
42 |
}
|
|
|
43 |
|
| 21165 |
ashik.ali |
44 |
@Bean(name = "viewResolver")
|
|
|
45 |
public InternalResourceViewResolver getViewResolver() {
|
| 25300 |
tejbeer |
46 |
LOGGER.debug("creating view resolver bean with prefix : " + PATH_PREFIX + " and suffix : " + PATH_SUFFIX);
|
| 21304 |
kshitij.so |
47 |
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
|
|
|
48 |
viewResolver.setPrefix(PATH_PREFIX);
|
|
|
49 |
viewResolver.setSuffix(PATH_SUFFIX);
|
|
|
50 |
return viewResolver;
|
| 21165 |
ashik.ali |
51 |
}
|
| 21304 |
kshitij.so |
52 |
|
| 25300 |
tejbeer |
53 |
@Bean(name = "messageSource")
|
| 21165 |
ashik.ali |
54 |
public ReloadableResourceBundleMessageSource getReloadableResourceBundleMessageSource() {
|
| 25300 |
tejbeer |
55 |
LOGGER.debug("creating messageSource bean with message path source name : " + MESSAGE_PATH_SOURCE_NAME);
|
|
|
56 |
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
|
| 21165 |
ashik.ali |
57 |
messageSource.setBasename(MESSAGE_PATH_SOURCE_NAME);
|
|
|
58 |
return messageSource;
|
|
|
59 |
}
|
| 21304 |
kshitij.so |
60 |
|
| 25300 |
tejbeer |
61 |
@Bean(name = "multipartResolver")
|
| 21165 |
ashik.ali |
62 |
public CommonsMultipartResolver getCommonsMultipartResolver() {
|
|
|
63 |
LOGGER.info("creating common multipart resolver bean");
|
| 24472 |
amit.gupta |
64 |
CommonsMultipartResolver multipartResolver = new CommonsMultipartResolver();
|
|
|
65 |
multipartResolver.setMaxUploadSizePerFile(5000000);
|
|
|
66 |
multipartResolver.setMaxUploadSize(5000000);
|
|
|
67 |
return multipartResolver;
|
| 21304 |
kshitij.so |
68 |
}
|
|
|
69 |
|
|
|
70 |
@Bean
|
| 21643 |
ashik.ali |
71 |
public PropertySourcesPlaceholderConfigurer propertyConfigurer1() {
|
| 21304 |
kshitij.so |
72 |
String activeProfile;
|
|
|
73 |
|
| 25300 |
tejbeer |
74 |
PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer = new PropertySourcesPlaceholderConfigurer();
|
|
|
75 |
|
| 21343 |
kshitij.so |
76 |
Properties properties = new Properties();
|
|
|
77 |
try {
|
|
|
78 |
properties.load(this.getClass().getClassLoader().getResourceAsStream("META-INF/env.property"));
|
|
|
79 |
} catch (IOException e) {
|
| 25300 |
tejbeer |
80 |
LOGGER.error("Error in reading env property file.Adding default property" + e);
|
| 21343 |
kshitij.so |
81 |
properties.put("profile", "dev");
|
|
|
82 |
}
|
|
|
83 |
activeProfile = (String) properties.get("profile");
|
| 21304 |
kshitij.so |
84 |
|
|
|
85 |
if ("prod".equals(activeProfile)) {
|
|
|
86 |
resource = new ClassPathResource("/META-INF/prod.properties");
|
|
|
87 |
} else if ("staging".equals(activeProfile)) {
|
| 21342 |
kshitij.so |
88 |
resource = new ClassPathResource("/META-INF/staging.properties");
|
| 21304 |
kshitij.so |
89 |
} else {
|
|
|
90 |
resource = new ClassPathResource("/META-INF/dev.properties");
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
propertySourcesPlaceholderConfigurer.setLocation(resource);
|
|
|
94 |
|
|
|
95 |
return propertySourcesPlaceholderConfigurer;
|
|
|
96 |
}
|
| 25300 |
tejbeer |
97 |
|
|
|
98 |
@Bean(name = "mailSender")
|
|
|
99 |
public JavaMailSender getGmailSender() {
|
|
|
100 |
JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
|
|
|
101 |
|
|
|
102 |
// Using gmail
|
|
|
103 |
mailSender.setHost("smtp.sendgrid.net");
|
|
|
104 |
mailSender.setPort(587);
|
|
|
105 |
mailSender.setUsername("shop2020");
|
|
|
106 |
mailSender.setPassword("U2/=fP,t");
|
|
|
107 |
|
|
|
108 |
Properties javaMailProperties = new Properties();
|
|
|
109 |
javaMailProperties.put("mail.smtp.starttls.enable", "false");
|
|
|
110 |
javaMailProperties.put("mail.smtp.auth", "true");
|
|
|
111 |
javaMailProperties.put("mail.transport.protocol", "smtp");
|
|
|
112 |
javaMailProperties.put("mail.debug", "true");// Prints out everything on screen
|
|
|
113 |
|
|
|
114 |
mailSender.setJavaMailProperties(javaMailProperties);
|
|
|
115 |
return mailSender;
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
@Bean(name = "gson")
|
|
|
119 |
public Gson gson() {
|
|
|
120 |
|
|
|
121 |
Gson gson = new GsonBuilder().setPrettyPrinting().serializeNulls()
|
|
|
122 |
.registerTypeAdapter(LocalDateTime.class, new LocalDateTimeJsonConverter()).create();
|
|
|
123 |
|
|
|
124 |
return gson;
|
|
|
125 |
|
|
|
126 |
}
|
|
|
127 |
|
| 21165 |
ashik.ali |
128 |
}
|