参考了很多文章,记录下自己的学习过程!
参考:https://blog.csdn.net/weixin_40776321/article/details/99633110
1. 在pom.xml中添加依赖:
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.1.20</version>
</dependency>
2. 在application-xxx.yaml中添加数据源配置
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://xx.xx.xx.xx:3306/DB?useSSL=false&useTimezone=true&serverTimezone=GMT%2B8&allowMultiQueries=true
username: root
password: 112233
driver-class-name: com.mysql.cj.jdbc.Driver
dbcp2:
min-idle: 3 # 数据库连接池的最小维持连接数
initial-size: 3
max-total: 5 # 最大的连接数
max-wait-millis: 200 # 等待连接获取的最大超时时间<