springBoot + druid
1.使用Spring initializer新建springBoot项目
2.选择springBoot包
3.pom文件新增druid依赖
<dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>1.1.10</version> </dependency>
4.编辑application.yml
#JDBC基本配置 spring: datasource: druid: #JDBC基本配置 url: jdbc:mysql://localhost:3306/test?useUnicode=true&allowPublicKeyRetrieval=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2b8 username: root password: 123 #如果不是mysql,换成对应的driver-class-name即可 driver-class-name: com.mysql.cj.jdbc.Driver #连接池配置 initial-size: 5 max-active: 100 min-idle: 5 max-wait: 60000 pool-prepared-statements: true max-pool-prepared-statement-per-connection-size: 20 validation-query: SELECT 1 FROM DUAL validation-query-timeout: 60000 test-on-borrow: false test-on-return: false test-while-idle: true time-between-eviction-runs-millis: 60000 min-evictable-idle-time-millis: 100000 ###监控配置 begin### web-stat-filter: # WebStatFilter配置,说明请参考Druid Wiki,配置_配置WebStatFilter enabled: true url-pattern: "/*" exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" stat-view-servlet: # StatViewServlet配置,说明请参考Druid Wiki,配置_StatViewServlet配置 enabled: true url-pattern: "/druid/*" reset-enable: false login-username: admin login-password: 123456 allow: 127.0.0.1 ###监控配置 end### filter: # 配置StatFilter stat: db-type: mysql log-slow-sql: true slow-sql-millis: 5000 # 配置WallFilter wall: enabled: true db-type: mysql config: delete-allow: false drop-table-allow: false
5.启动项目访问http://localhost:8080/druid
6.输入配置文件配置的用户名密码 admin 123456 即可进入druid的监控界面
源代码:https://github.com/guanxiaohe2017/druid-demo
⎛⎝官萧何⎠⎞一只快乐的爪哇程序猿;邮箱:1570608034@qq.com