springboot 整合druid

发布时间:2022-06-28 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了springboot 整合druid脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

druid 官方文档 : druid/druid-sPRing-boot-starter at master · alibaba/druid (gIThub.COM)

配置依赖

jdbc 依赖、数据库依赖(MySQL),druid 依赖

    <dePEndency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.1.17</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jdbc</artifactId>
    </dependency>
    <dependency>
        <groupId>;mySQL</groupId>
        <artifactId>mysql-connector-java</artifactId>
    </dependency>

基本-配置信息

  • 在 application.yaML
spring:
#  数据库
  datasource:
    url: jdbc:mysql://localhost:3306/test?useSSL=false&amp;serverTimezone=UTC&allowPublicKeyRetrieval=true&characterEncoding=utf-8
    username: root
    password: root
  • 做一个简单的查询,测试结果如图:

springboot 整合druid

扩展-配置 druid 监控功能

  • 在 spring-datasource 下

配置火墙、监控页,开启web监控

spring:

#  数据库
  datasource:
    url: jdbc:mysql://localhost:3306/test?useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true&characterEncoding=utf-8
    username: root
    password: root

    # druid 配置
    druid:
      # 配置监控防火墙功能
      filters: stat,wall # 这两个详细参数可通过 filter-xxx 配置
      filter:
        stat:
          enabled: true
          slow-sql-millis: 1000 # 设置 1000ms 为慢查询
          LOG-slow-sql: true  # 开启慢查询监控
        wall: # 在这里可配置 不允许更新、不允许删除等操作
          enabled: true

      # 开启监控页,并配置账号密码
      stat-view-servlet:
        enabled: true
        login-username: admin
        login-password: admin
        # reset-enable: false # 重置按钮

      # 开启web 监控功能。 urlPattern 和 exclusions 有默认值
      web-stat-filter:
        enabled: true

      # aop-patterns: cc.acdongla.boot.* 配置监控包



  • 启动项目后, http://localhost:8080/druid/ 可进入 druid 的监控页

springboot 整合druid

脚本宝典总结

以上是脚本宝典为你收集整理的springboot 整合druid全部内容,希望文章能够帮你解决springboot 整合druid所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。