Springboot +druid 配置SQL监控界面

第一步:

pom.xml  调整此配置文件,这几个配置必须得有。

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid</artifactId>
            <version>1.1.14</version>
        </dependency>
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.1.14</version>
        </dependency>
        <!-- mysql驱动 -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.11</version>
        </dependency>

        <!-- JDBC 依赖 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
            <version>2.6.2</version>
        </dependency>

第二步:

yml配置文件调整。

# 端口设置
server:
  port: 8083
spring:
  # 项目名称设置
  application:
    name: springboot-ew-tools
  #数据库链接配置
  datasource: 
    type: com.alibaba.druid.pool.DruidDataSource
    url: jdbc:mysql://192.168.2.232:7701/ew?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true&serverTimezone=Asia/Shanghai&useSSL=false
    username: root
    password: 123456
    # mysql8.0配置需要带‘cj’
    driver-class-name: com.mysql.cj.jdbc.Driver
    validationQuery: SELECT 1 FROM DUAL
    testWhileIdle: true
    testOnBorrow: false
    testOnReturn: false
    logSlowSql: true 
    poolPreparedStatements: false
    maxOpenPreparedStatements: 20
    druid:
      initial-size: 5
      max-active: 20
      min-idle: 10
      max-wait: 10
      filters: stat,wall
      filter:
        stat:
          log-slow-sql: true
          slow-sql-millis: 2000

      #配置WebStatFilter
      web-stat-filter:
        enabled: true
        url-pattern: /*
        exclusions: '*.gif,*.png,*.jpg,*.html,*.js,*.css,*.ico,/druid/*'

      #配置StatViewServlet配置
      stat-view-servlet:
        enabled: true
        url-pattern: /druid/*
        reset-enable: true
        login-username: admin
        login-password: admin
        allow: localhost
        deny: 
# 日志配置
logging:
  config: D:/tool_work/logs_config/logback-${spring.application.name}.xml

第三步:

Sorry, you are not permitted to view this page.

如果过程中发现以上错误提示,则记得配置stat-view-servlet.allow=localhost

Springboot +druid 配置SQL监控界面

登录用户名和密码为配置信息,参数:stat-view-servlet.login-username,stat-view-servlet.login-password

登录成功后,显示如下界面:

Springboot +druid 配置SQL监控界面

 

 

 

上一篇:springboot中druid连接密码加密


下一篇:推荐系统中双塔模型损失函数设计