Subversion Repositories SmartDukaan

Rev

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

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