springboot在哪个文件初始化连接池的
时间: 2024-03-17 17:40:59 浏览: 26
在 Spring Boot 中,我们可以使用 Spring Boot Starter JDBC 或者 Spring Boot Starter Data JDBC 来快速集成数据库连接池。这两个 Starter 底层都是使用 HikariCP 数据库连接池来管理数据库连接的。
在 Spring Boot 中,我们可以通过在 application.properties 或 application.yml 文件中配置数据库相关的属性来初始化连接池。具体配置方式如下:
application.properties 配置文件:
```
# 数据库连接配置
spring.datasource.url=jdbc:mysql://localhost:3306/test
spring.datasource.username=root
spring.datasource.password=root
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
# HikariCP 连接池属性配置
spring.datasource.hikari.connectionTimeout=30000
spring.datasource.hikari.maximumPoolSize=5
spring.datasource.hikari.minimumIdle=1
spring.datasource.hikari.idleTimeout=600000
```
application.yml 配置文件:
```
# 数据库连接配置
spring:
datasource:
url: jdbc:mysql://localhost:3306/test
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
# HikariCP 连接池属性配置
datasource:
hikari:
connectionTimeout: 30000
maximumPoolSize: 5
minimumIdle: 1
idleTimeout: 600000
```
在上述配置中,我们通过 spring.datasource.* 前缀来配置数据库连接相关的属性,通过 spring.datasource.hikari.* 前缀来配置 HikariCP 连接池相关的属性。
当 Spring Boot 应用启动时,会自动读取这些配置项,并使用它们来初始化 HikariCP 连接池。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)