• springboot 梳理2--配置druid数据源


    1. pom.xml添加

    <!--德鲁伊数据源-->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>druid</artifactId>
                <version>1.1.18</version>
            </dependency>

    2. yml

    spring:
      #默认datasource hikaricp
      datasource:
        url: jdbc:mysql://127.0.0.1:3306/ssm?characterEncoding=utf8&&useSSL=false&serverTimezone=UTC&rewriteBatchedStatements=true
        driver-class-name: com.mysql.jdbc.Driver
        username: root
        password: 123456
        type: com.alibaba.druid.pool.DruidDataSource
    
        #数据源其他配置
        initialSize: 5
        minIdle: 5
        maxActive: 20
        maxWait: 60000
        timeBetweenEvictionRunsMillis: 60000
        minEvictableIdleTimeMillis: 300000
        validationQuery: SELECT 1 FROM DUAL
        testWhileIdle: true
        testonBorrow: false
        testOnReturn: false
        poolPreparedStatements: true
        #配置监控统计拦截的fi1ters,去掉后监控界面sq1无法统计,'wall'用于防火墙
        filters : stat,wall
        maxPoolPreparedstatementPerconnectionsize: 20
        useG1oba1Datasourcestat: true
        connectionProperties: druid.stat.mergeSq1=true;druid.stat.s1owSq1Mi11is=500

    3. conf层下,DruidConfig

    @Configuration
    public class DruidConfig {
        //把yml里面的设置文件放进去
        @ConfigurationProperties(prefix = "spring.datasource")
        @Bean
        public DataSource druid(){
            return new DruidDataSource();
        }


    //可以放其他

    }

    里面可以放,配置监控

    /**
        *配置监控
        * @return
        */
        @Bean
        public ServletRegistrationBean statviewservlet() {
            ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
            HashMap<String, String> map = new HashMap<>(2);
            map.put("loginUsername", "sr");
            map.put("loginPassword", "123456");
            bean.setInitParameters(map);
            return bean;
        }
    
        @Bean
        public FilterRegistrationBean webStatFilter(){
            FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<>();bean.setFilter(new WebStatFilter());
            HashMap<String,String> map = new HashMap<>(8);
            map.put("exclusions " , "*.js ");
            map.put("exclusions " , "*.css ");
            map.put("exclusions " , "*.html ");
            map.put("exclusions " , "*.jpg ");
            bean.setInitParameters (map);
            bean.setUrlPatterns (Arrays.asList("/*"));

    return bean; }
  • 相关阅读:
    html5shiv.js-让IE浏览器支持HTML5标准
    CSS2系列:外边距合并问题(margincollapse)
    HTML5:离线存储(缓存机制)-IndexDB
    CSS3系列:流式(弹性)布局(flex布局)
    Sublime Text 3 常用插件以及安装方法(转)
    后台配置参数写在文件上
    20160414
    2016413
    20160412
    网页设计素材网站
  • 原文地址:https://www.cnblogs.com/Master-Sun/p/14344556.html
Copyright © 2020-2023  润新知