在pom中添加starter依赖
com.alibaba druid-spring-boot-starter 1.1.4
在properties中添加连接池配置
## DBspring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver# JDBC url of the database.spring.datasource.url= jdbc:mysql://127.0.0.1:3306/?useUnicode=true&characterEncoding=utf-8&useSSL=false # Login user of the database. spring.datasource.username= xxx# Name of the datasource.spring.datasource.name=test# Login password of the database.spring.datasource.password=xxxspring.jooq.sql-dialect=mysqlspring.datasource.druid.max-active=15##druid viewspring.datasource.druid.stat-view-servlet.url-pattern=/druid/*spring.datasource.druid.stat-view-servlet.login-username=adminspring.datasource.druid.stat-view-servlet.login-password=admin888spring.datasource.druid.aop-patterns=com.demo.service.*spring.aop.proxy-target-class=true
启动spring boot,浏览器中输入http://localhost:8080/druid/login.html,使用配置中的用户名密码登录进入druid stat view页面
druid官方stater对于配置spring aop中部分源代码:
详细配置请参考druid官方:
https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter