//package com.fdkankan.db.config;
//
//import com.alibaba.druid.pool.DruidDataSource;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.boot.context.properties.ConfigurationProperties;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.context.annotation.Primary;
//
//import javax.sql.DataSource;
//import java.sql.SQLException;
//
///**
// * druid连接池配置
// */
//@Configuration
//public class DruidConfiguration {
//
//    @Value("${spring.datasource.url}")
//    private String url;
//
//    @Value("${spring.datasource.username}")
//    private String username;
//
//    @Value("${spring.datasource.password}")
//    private String password;
//
//    @Value("${spring.datasource.driver-class-name}")
//    private String driverClassName;
//
//    @Value("${spring.druid.initialSize}")
//    private int initialSize;
//
//    @Value("${spring.druid.minIdle}")
//    private int minIdle;
//
//    @Value("${spring.druid.maxActive}")
//    private int maxActive;
//
//    @Value("${spring.druid.maxWait}")
//    private int maxWait;
////
//    @Value("${spring.druid.timeBetweenEvictionRunsMillis}")
//    private int timeBetweenEvictionRunsMillis;
//
//    @Value("${spring.druid.minEvictableIdleTimeMillis}")
//    private int minEvictableIdleTimeMillis;
//
//    @Value("${spring.druid.validationQuery}")
//    private String validationQuery;
//
//    @Value("${spring.druid.testWhileIdle}")
//    private boolean testWhileIdle;
//
//    @Value("${spring.druid.testOnBorrow}")
//    private boolean testOnBorrow;
//
//    @Value("${spring.druid.testOnReturn}")
//    private boolean testOnReturn;
//
//    @Value("${spring.druid.poolPreparedStatements}")
//    private boolean poolPreparedStatements;
//
//    @Value("${spring.druid.keepAlive}")
//    private boolean keepAlive;
////    @Value("${spring.druid.maxPoolPreparedStatementPerConnectionSize}")
////    private int maxPoolPreparedStatementPerConnectionSize;
////
////    @Value("${spring.druid.filters}")
////    private String filters;
////
////    @Value("{spring.druid.connectionProperties}")
////    private String connectionProperties;
//
//    @Bean(name = "dataSource")
//    @Primary
//    public DataSource dataSource() throws SQLException {
//        DruidDataSource datasource = new DruidDataSource();
//
//        datasource.setUrl(url);
//        datasource.setUsername(username);
//        //这里可以做加密处理
//        datasource.setPassword(password);
//        datasource.setDriverClassName(driverClassName);
//
//        //配置了初始化连接池大小，本地启动初始化连接时会很慢，服务器上启动并不慢
//        datasource.setInitialSize(initialSize);
//        datasource.setMinIdle(minIdle);
//        datasource.setMaxActive(maxActive);
//        datasource.setMaxWait(maxWait);
//        datasource.setKeepAlive(keepAlive);
//        datasource.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
//        datasource.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
//        datasource.setValidationQuery(validationQuery);
//        datasource.setTestWhileIdle(testWhileIdle);
//        datasource.setTestOnBorrow(testOnBorrow);
//        datasource.setTestOnReturn(testOnReturn);
//        datasource.setPoolPreparedStatements(poolPreparedStatements);
////        datasource.setMaxPoolPreparedStatementPerConnectionSize(maxPoolPreparedStatementPerConnectionSize);
////        try {
////            datasource.setFilters(filters);
////            List<Filter> wallFilters = new ArrayList<>();
////            wallFilters.add((Filter) wallFilter());
////            datasource.setProxyFilters(wallFilters);
////        } catch (SQLException e) {
////
////        }
////        datasource.setConnectionProperties(connectionProperties);
//        datasource.init();
//
//        return datasource;
//    }
//
////    /**
////     * StatViewServlet用于展示Druid的统计信息
////     * 地址为：http://ip:/port/druid/index.html
////     * @return
////     */
////    @Bean
////    public ServletRegistrationBean statViewServlet() {
////        ServletRegistrationBean servletRegistrationBean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
////        //设置ip白名单
////        //servletRegistrationBean.addInitParameter("allow", "127.0.0.1");
////        //设置ip黑名单，优先级高于白名单
////        //servletRegistrationBean.addInitParameter("deny", "192.168.0.19");
////        //设置控制台管理用户
////        servletRegistrationBean.addInitParameter("loginUsername", "root");
////        servletRegistrationBean.addInitParameter("loginPassword", "root");
////        //是否可以重置数据
////        servletRegistrationBean.addInitParameter("resetEnable", "false");
////        return servletRegistrationBean;
////    }
////
////    /**
////     * Druid监控拦截器
////     * @return
////     */
////    @Bean
////    public FilterRegistrationBean statFilter() {
////        //创建过滤器
////        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean(new WebStatFilter());
////        //设置过滤器过滤路径
////        filterRegistrationBean.addUrlPatterns("/*");
////        //忽略过滤的形式 关键字：exclusions
////        filterRegistrationBean.addInitParameter("exclusions", "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*,/static/*");
////        return filterRegistrationBean;
////    }
////
////    @Bean
////    public WallFilterMBean wallFilter(){
////        WallFilter wallFilterMBean = new WallFilter();
////        wallFilterMBean.setConfig(wallConfig());
////        return wallFilterMBean;
////    }
////
////    @Bean
////    public WallConfig wallConfig(){
////        WallConfig wallConfig = new WallConfig();
////        wallConfig.setMultiStatementAllow(true);//允许一次执行多条语句
////        wallConfig.setNoneBaseStatementAllow(true);//允许一次执行多条语句
////        return wallConfig;
////    }
//
//}