pom文件
1 2 3 4 5
| <dependency> <groupId>com.alibaba</groupId> <artifactId>druid-spring-boot-starter</artifactId> <version>RELEASE</version> </dependency>
|
yml文件
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
| spring: datasource: druid: username: root password: 123456 url: jdbc:mysql://127.0.0.1:3306/springboot?serverTimezone=GMT%2B8&characterEncoding=UTF-8&useSSL=false driver-class-name: com.mysql.cj.jdbc.Driver initial-size: 5 min-idle: 5 max-active: 20 max-wait: 120000 time-between-eviction-runs-millis: 60000 min-evictable-idle-time-millis: 300000 validation-query: SELECT 'x' test-while-idle: true test-on-borrow: false test-on-return: false poolPreparedStatements: true maxPoolPreparedStatementPerConnectionSize: 20 filter: stat: log-slow-sql: true slow-sql-millis: 2000 enabled: true wall: enabled: true web-stat-filter: enabled: true url-pattern: /* exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico,/druid/*" session-stat-enable: false session-stat-max-count: 1000 principal-cookie-name: admin principal-session-name: admin profile-enable: true stat-view-servlet: enabled: true url-pattern: /druid/* reset-enable: true login-username: admin login-password: 123456 allow: deny:
|
编写以上配置后,监控页面一直报:(*)property for user to setup,后面才发现,数据源根本没有注入成功
在yml中添加以下代码,即可解决
1 2 3 4
| spring: datasource: type: com.alibaba.druid.pool.DruidDataSource
|
参考:
https://github.com/alibaba/druid/tree/master/druid-spring-boot-starter