springboot database connection pool used druid

1. introduced maven dependent

<!-- https://mvnrepository.com/artifact/com.alibaba/druid -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.10</version>
        </dependency>

 

2. Write configuration information application.yml

the Spring: 
    the DataSource: 
      of the type: com.alibaba.druid.pool.DruidDataSource 
      url: jdbc: MySQL: // 127.0.0.1:3306/seckill?serverTimezone=UTC 
      username: root 
      password: root 
      Driver - class - name: com.mysql. cj.jdbc.Driver 
# connection pool is provided below, applied to the above data sources (some basic settings) 
      # initial size 
      initialSize: . 5 
      # minimum 
      minIdle: . 5 
      # maximum 
      for maxActive: 20 is 
      # acquires connection waiting timeout 
      maxWait: 60,000

 

3. Write configuration class

// This ensures minimum run up 
@Configuration
public class DruidConfig { @Bean @ConfigurationProperties (prefix = "spring.datasource" ) public the DataSource Druid () { return new new DruidDataSource (); } }

 

Guess you like

Origin www.cnblogs.com/olzoooo/p/11276607.html