创建spring boot项目,在pom中添加相应依赖

<!--web-->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<!--mysql-->
<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<scope>runtime</scope>
</dependency>

<!--druid-->
<dependency>
	<groupId>com.alibaba</groupId>
	<artifactId>druid-spring-boot-starter</artifactId>
	<version>1.1.10</version>
</dependency>

<!--jdbc-->
<dependency>
	<groupId>org.springframework</groupId>
	<artifactId>spring-jdbc</artifactId>
</dependency>

在application.yml文件中配置数据源

spring:
  application:
    name: cloud-account
  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访问Druid后台监控界面。