• 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; }
  • 相关阅读:
    django-02框架-配置、静态文件和路由
    django-01框架-工程搭建
    python虚拟环境安装
    linux推送文件到另一台主机
    python2问题收集
    python diff json方法
    Linux expect详解
    python scp到远端机器
    shell远程执行命令(命令行与脚本)
    git操作
  • 原文地址:https://www.cnblogs.com/Master-Sun/p/14344556.html
Copyright © 2020-2023  润新知