Created
March 2, 2014 05:23
-
-
Save sivaprasadreddy/9302313 to your computer and use it in GitHub Desktop.
AppConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.sivalabs.springapp.config; | |
import java.util.Properties; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.cache.CacheManager; | |
import org.springframework.cache.annotation.EnableCaching; | |
import org.springframework.cache.concurrent.ConcurrentMapCacheManager; | |
import org.springframework.context.annotation.Bean; | |
import org.springframework.context.annotation.ComponentScan; | |
import org.springframework.context.annotation.Configuration; | |
import org.springframework.context.annotation.EnableAspectJAutoProxy; | |
import org.springframework.context.annotation.FilterType; | |
import org.springframework.context.annotation.PropertySource; | |
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; | |
import org.springframework.core.env.Environment; | |
import org.springframework.mail.javamail.JavaMailSenderImpl; | |
import org.springframework.scheduling.annotation.EnableScheduling; | |
@Configuration | |
@ComponentScan(basePackages={"com.sivalabs.springapp"}, | |
excludeFilters=@ComponentScan.Filter(type=FilterType.REGEX, pattern={"com.sivalabs.springapp.web.*"})) | |
@PropertySource(value = { "classpath:application.properties" }) | |
@EnableScheduling | |
@EnableAspectJAutoProxy | |
@EnableCaching | |
public class AppConfig | |
{ | |
@Autowired | |
private Environment env; | |
@Bean | |
public static PropertySourcesPlaceholderConfigurer placeHolderConfigurer() | |
{ | |
return new PropertySourcesPlaceholderConfigurer(); | |
} | |
@Bean | |
public JavaMailSenderImpl javaMailSenderImpl() { | |
JavaMailSenderImpl mailSenderImpl = new JavaMailSenderImpl(); | |
mailSenderImpl.setHost(env.getProperty("smtp.host")); | |
mailSenderImpl.setPort(env.getProperty("smtp.port", Integer.class)); | |
mailSenderImpl.setProtocol(env.getProperty("smtp.protocol")); | |
mailSenderImpl.setUsername(env.getProperty("smtp.username")); | |
mailSenderImpl.setPassword(env.getProperty("smtp.password")); | |
Properties javaMailProps = new Properties(); | |
javaMailProps.put("mail.smtp.auth", true); | |
javaMailProps.put("mail.smtp.starttls.enable", true); | |
mailSenderImpl.setJavaMailProperties(javaMailProps); | |
return mailSenderImpl; | |
} | |
@Bean | |
public CacheManager cacheManager() | |
{ | |
return new ConcurrentMapCacheManager(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment