在pom中添加starter依賴html
<dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.4</version> </dependency>
在properties中添加鏈接池配置mysql
## DB spring.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=xxx spring.jooq.sql-dialect=mysql spring.datasource.druid.max-active=15 ##druid view spring.datasource.druid.stat-view-servlet.url-pattern=/druid/* spring.datasource.druid.stat-view-servlet.login-username=admin spring.datasource.druid.stat-view-servlet.login-password=admin888 spring.datasource.druid.aop-patterns=com.demo.service.* spring.aop.proxy-target-class=true
啓動spring boot,瀏覽器中輸入http://localhost:8080/druid/login.html,使用配置中的用戶名密碼登陸進入druid stat view頁面git
druid官方stater對於配置spring aop中部分源代碼:github
詳細配置請參考druid官方:spring
https://github.com/alibaba/druid/tree/master/druid-spring-boot-startersql