Springboot +druid 配置SQL监控界面

第一步:

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

        
            com.alibaba
            druid
            1.1.14
        
        
            com.alibaba
            druid-spring-boot-starter
            1.1.14
        
        
        
            mysql
            mysql-connector-java
            8.0.11
        

        
        
            org.springframework.boot
            spring-boot-starter-jdbc
            2.6.2
        

第二步:

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监控界面_第1张图片

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

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

Springboot +druid 配置SQL监控界面_第2张图片

 

 

 

你可能感兴趣的:(日常记录,spring,boot,sql,mysql)