springboot druid database connection

Ali cloud druid is efficient open source database connection project

gubpub: https://github.com/alibaba/druid

 

meven arrangement

<dependency>
   <groupId>com.alibaba</groupId>
   <artifactId>druid-spring-boot-starter</artifactId>
   <version>1.1.13</version>
</dependency>

sprinboot scan

@Configuration
 public  class DruidConfig {
     // This annotation reads the configuration file prefix prefix configuration, the external profile herein bind 
    @ConfigurationProperties (prefix = "spring.druid" )
     // turn on and off the container 
    @Bean ( = the initMethod "the init", and destroyMethod = "Close" )
     public DruidDataSource the dataSource () { 
        DruidDataSource the dataSource = new new DruidDataSource (); 
        dataSource.setProxyFilters (Lists.newArrayList (statFilter ())); 
        return   the dataSource; 
    } 
    // the bean annotations become the spring bean, using the slow filter sql print log 
    @Bean
     public the filter statFilter () {
        StatFilter StatFilter  =new new StatFilter ();
         // How long is defined as slow sql, here defined as 5S 
        statFilter.setSlowSqlMillis (5000 );
         // whether to print out the slow log 
        statFilter.setLogSlowSql ( to true );
         // whether to log merge 
        statFilter .setMergeSql ( to true );
         return   statFilter; 
    } 
    // this is the configuration druid monitoring 
    @Bean
     public ServletRegistrationBean servletRegistrationBean () {
         return  new new ServletRegistrationBean ( new new StatViewServlet (), "/ druid / *" ); 
    }
 
}

yum database configuration

Spring: 
    Druid: 
        druidClassName: com.mysql.cj.jdbc.Driver 
        URL: ******* 
        username: **** 
        password: **** 
        # The maximum number of connections 
        for maxActive: 30 
        # minimum number of connections 
        minIdle: . 5 
        # the maximum waiting time to get a connection 
        maxWait: 10000 
        # mysql8 hours to solve a problem 
        validationgQuery: the SELECT 'the X-' 
        check time # idle connection interval 
        timeBetweenEvictionRunsMillis: 60000 
        # idle connection minimum idle time 
        minEvictableIdleTimeMillis: 300000

 

Guess you like

Origin www.cnblogs.com/baobaoxiaokeai/p/10966399.html