创建spring boot项目,在pom中添加相应依赖
org.springframework.boot
spring-boot-starter-web
mysql
mysql-connector-java
runtime
com.alibaba
druid-spring-boot-starter
1.1.10
org.springframework
spring-jdbc
在application.yml文件中配置数据源
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://localhost:3306/db?serverTimezone=UTC&useUnicode=true&characterEncoding=utf-8&useSSL=true
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: root
druid:
initial-size: 3
min-idle: 3
max-active: 10
max-wait: 60000
stat-view-servlet:
login-username: admin
login-password: admin
filter:
stat:
log-slow-sql: true
slow-sql-millis: 2000
启动后可以通过:http:hostname:port/druid/index.html