@Configuration@EnableAspectJAutoProxy(proxyTargetClass = true)**public class DruidAspectConfig {
@Bean
public DruidStatInterceptor druidStatInterceptor() {
DruidStatInterceptor dsInterceptor = new DruidStatInterceptor();
return dsInterceptor;
}
@Bean
@Scope("prototype")
public JdkRegexpMethodPointcut druidStatPointcut() {
JdkRegexpMethodPointcut pointcut = new JdkRegexpMethodPointcut();
pointcut.setPatterns("com.xxx.dao.*","com.xxx.service.*");
return pointcut;
}
@Bean
public DefaultPointcutAdvisor druidStatAdvisor(DruidStatInterceptor druidStatInterceptor, JdkRegexpMethodPointcut druidStatPointcut) {
DefaultPointcutAdvisor defaultPointAdvisor = new DefaultPointcutAdvisor();
defaultPointAdvisor.setPointcut(druidStatPointcut);
defaultPointAdvisor.setAdvice(druidStatInterceptor);
return defaultPointAdvisor;
}
}
@Configurationpublic class DruidConfig {
@Bean
public Slf4jLogFilter logFilter () {
Slf4jLogFilter logFilter = new Slf4jLogFilter();
logFilter.setStatementExecutableSqlLogEnable(true);
logFilter.setStatementLogEnabled(false);
return logFilter;
}
@Bean
public StatFilter statFilter () {
StatFilter statFilter = new StatFilter();
statFilter.setSlowSqlMillis(3000);
statFilter.setLogSlowSql(true);
statFilter.setMergeSql(true);
return statFilter;
}
/**
* sql防火墙过滤器配置
* @param wallConfig
* @return
*/
@Bean
public WallFilter wallFilter (WallConfig wallConfig) {
WallFilter wallFilter = new WallFilter();
wallFilter.setConfig(wallConfig);
wallFilter.setLogViolation(true);//对被认为是攻击的SQL进行LOG.error输出
wallFilter.setThrowException(false);//对被认为是攻击的SQL抛出SQLException
return wallFilter;
}
/**
* sql防火墙配置
* @return
*/
@Bean
public WallConfig wallConfig () {
WallConfig wallConfig = new WallConfig();
wallConfig.setAlterTableAllow(false);
wallConfig.setCreateTableAllow(false);
wallConfig.setDeleteAllow(false);
wallConfig.setMergeAllow(false);
wallConfig.setDescribeAllow(false);
wallConfig.setShowAllow(false);
return wallConfig;
}
}