Commit a0f78a36 by fsn

重新整理配置结构

parent ae2c4080
package com.stylefeng.guns.config; package com.stylefeng.guns.config;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.spring.stat.BeanTypeAutoProxyCreator;
import com.alibaba.druid.support.spring.stat.DruidStatInterceptor;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import com.stylefeng.guns.core.intercept.SessionInterceptor;
import net.sf.ehcache.CacheManager; import net.sf.ehcache.CacheManager;
import org.springframework.cache.ehcache.EhCacheCacheManager; import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerFactoryBean; import org.springframework.cache.ehcache.EhCacheManagerFactoryBean;
...@@ -13,8 +7,6 @@ import org.springframework.context.annotation.Bean; ...@@ -13,8 +7,6 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
import java.util.Properties;
/** /**
* 其他bean的配置 * 其他bean的配置
* *
...@@ -22,7 +14,7 @@ import java.util.Properties; ...@@ -22,7 +14,7 @@ import java.util.Properties;
* @date 2017-05-20 23:11 * @date 2017-05-20 23:11
*/ */
@Configuration @Configuration
public class OtherConfigs { public class EhCacheConfig {
/** /**
* EhCache的配置 * EhCache的配置
...@@ -31,54 +23,14 @@ public class OtherConfigs { ...@@ -31,54 +23,14 @@ public class OtherConfigs {
public EhCacheCacheManager cacheManager(CacheManager cacheManager) { public EhCacheCacheManager cacheManager(CacheManager cacheManager) {
return new EhCacheCacheManager(cacheManager); return new EhCacheCacheManager(cacheManager);
} }
/**
* EhCache的配置
*/
@Bean @Bean
public EhCacheManagerFactoryBean ehcache() { public EhCacheManagerFactoryBean ehcache() {
EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean(); EhCacheManagerFactoryBean ehCacheManagerFactoryBean = new EhCacheManagerFactoryBean();
ehCacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml")); ehCacheManagerFactoryBean.setConfigLocation(new ClassPathResource("ehcache.xml"));
return ehCacheManagerFactoryBean; return ehCacheManagerFactoryBean;
} }
/**
* 验证码生成相关
*/
@Bean
public DefaultKaptcha kaptcha() {
Properties properties = new Properties();
properties.put("kaptcha.border", "no");
properties.put("kaptcha.border.color", "105,179,90");
properties.put("kaptcha.textproducer.font.color", "blue");
properties.put("kaptcha.image.width", "125");
properties.put("kaptcha.image.height", "45");
properties.put("kaptcha.textproducer.font.size", "45");
properties.put("kaptcha.session.key", "code");
properties.put("kaptcha.textproducer.char.length", "4");
properties.put("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑");
Config config = new Config(properties);
DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
defaultKaptcha.setConfig(config);
return defaultKaptcha;
}
/**
* session的拦截器,用在非controller层调用session
*/
@Bean
public SessionInterceptor sessionInterceptor() {
return new SessionInterceptor();
}
/**
* druid数据库连接池监控
*/
@Bean
public DruidStatInterceptor druidStatInterceptor() {
return new DruidStatInterceptor();
}
@Bean
public BeanTypeAutoProxyCreator beanTypeAutoProxyCreator() {
BeanTypeAutoProxyCreator beanTypeAutoProxyCreator = new BeanTypeAutoProxyCreator();
beanTypeAutoProxyCreator.setTargetBeanType(DruidDataSource.class);
beanTypeAutoProxyCreator.setInterceptorNames("druidStatInterceptor");
return beanTypeAutoProxyCreator;
}
} }
...@@ -20,9 +20,6 @@ import org.springframework.context.annotation.Configuration; ...@@ -20,9 +20,6 @@ import org.springframework.context.annotation.Configuration;
public class MybatisPlusConfig { public class MybatisPlusConfig {
@Autowired @Autowired
DruidProperties databaseProperties;
@Autowired
DruidProperties druidProperties; DruidProperties druidProperties;
/** /**
......
package com.stylefeng.guns.config.web; package com.stylefeng.guns.config.web;
import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.support.http.StatViewServlet; import com.alibaba.druid.support.http.StatViewServlet;
import com.alibaba.druid.support.spring.stat.BeanTypeAutoProxyCreator;
import com.alibaba.druid.support.spring.stat.DruidStatInterceptor;
import com.google.code.kaptcha.impl.DefaultKaptcha;
import com.google.code.kaptcha.util.Config;
import com.stylefeng.guns.core.intercept.SessionInterceptor;
import com.stylefeng.guns.core.listener.ConfigListener; import com.stylefeng.guns.core.listener.ConfigListener;
import com.stylefeng.guns.core.util.xss.XssFilter; import com.stylefeng.guns.core.util.xss.XssFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean; import org.springframework.boot.web.servlet.FilterRegistrationBean;
...@@ -10,6 +16,8 @@ import org.springframework.context.annotation.Bean; ...@@ -10,6 +16,8 @@ import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextListener; import org.springframework.web.context.request.RequestContextListener;
import java.util.Properties;
/** /**
* web 配置类 * web 配置类
* *
...@@ -30,6 +38,25 @@ public class WebConfig { ...@@ -30,6 +38,25 @@ public class WebConfig {
} }
/** /**
* druid数据库连接池监控
*/
@Bean
public DruidStatInterceptor druidStatInterceptor() {
return new DruidStatInterceptor();
}
/**
* druid数据库连接池监控
*/
@Bean
public BeanTypeAutoProxyCreator beanTypeAutoProxyCreator() {
BeanTypeAutoProxyCreator beanTypeAutoProxyCreator = new BeanTypeAutoProxyCreator();
beanTypeAutoProxyCreator.setTargetBeanType(DruidDataSource.class);
beanTypeAutoProxyCreator.setInterceptorNames("druidStatInterceptor");
return beanTypeAutoProxyCreator;
}
/**
* xssFilter注册 * xssFilter注册
*/ */
@Bean @Bean
...@@ -54,4 +81,33 @@ public class WebConfig { ...@@ -54,4 +81,33 @@ public class WebConfig {
public ServletListenerRegistrationBean<ConfigListener> configListenerRegistration() { public ServletListenerRegistrationBean<ConfigListener> configListenerRegistration() {
return new ServletListenerRegistrationBean<>(new ConfigListener()); return new ServletListenerRegistrationBean<>(new ConfigListener());
} }
/**
* session的拦截器,用在非controller层调用session
*/
@Bean
public SessionInterceptor sessionInterceptor() {
return new SessionInterceptor();
}
/**
* 验证码生成相关
*/
@Bean
public DefaultKaptcha kaptcha() {
Properties properties = new Properties();
properties.put("kaptcha.border", "no");
properties.put("kaptcha.border.color", "105,179,90");
properties.put("kaptcha.textproducer.font.color", "blue");
properties.put("kaptcha.image.width", "125");
properties.put("kaptcha.image.height", "45");
properties.put("kaptcha.textproducer.font.size", "45");
properties.put("kaptcha.session.key", "code");
properties.put("kaptcha.textproducer.char.length", "4");
properties.put("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑");
Config config = new Config(properties);
DefaultKaptcha defaultKaptcha = new DefaultKaptcha();
defaultKaptcha.setConfig(config);
return defaultKaptcha;
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment