当前位置:Gxlcms > 数据库问题 > 第13章—数据库连接池(Druid)

第13章—数据库连接池(Druid)

时间:2021-07-01 10:21:17 帮助过:39人阅读

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

 

二、添加配置

spring:
  datasource:
    url: jdbc:mysql://localhost:3306/test
    username: root
    password: root
    driver-class-name: com.mysql.jdbc.Driver
    type: com.alibaba.druid.pool.DruidDataSource
    druid:
      #最大连接池数量
      max-active: 20
      #初始化大小
      initial-size: 1
      #最小连接池数量
      min-idle: 3
      # 配置获取连接等待超时的时间
      max-wait: 60000
      # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
      time-between-eviction-runs-millis: 60000
      # 配置一个连接在池中最小生存的时间,单位是毫秒
      min-evictable-idle-time-millis: 300000
      # 检测连接是否有效的sql
      test-while-idle: true
      test-on-borrow: false
      test-on-return: false
      #PSCache Mysql下建议关闭
      poolPreparedStatements: true
      statViewServlet:
        #登录帐号
        login-username: druid
        #登录密码
        login-password: druid

  jpa:
    hibernate:
      ddl-auto: update
    show-sql: true    

更多配置,请参考这里

 

三、启动测试

启动项目,访问http://localhost:8080/druid 首先输入上面配置的用户名和密码 druid 进行登录:

技术分享图片

执行一个查询请求,然后查看SQL监控页面:

技术分享图片

 查看数据源页面:

技术分享图片

 如果用1.1.0以前版本,进行配置的。启动后直接查看数据源页面只显示(*) property for user to setup,详见这里

技术分享图片

 

第13章—数据库连接池(Druid)

标签:size   log4   安全   enc   localhost   setup   jdk   while   commons   

人气教程排行