Subversion Repositories SmartDukaan

Rev

Rev 23568 | Rev 25300 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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