springboot的yml文件中关于连接池以及事务超时机制的配置
时间: 2024-05-14 08:17:12 浏览: 96
关于连接池的配置,可以在yml文件中设置以下参数:
```
spring.datasource:
url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
# 下面是Hikari连接池的相关配置
type: com.zaxxer.hikari.HikariDataSource
hikari:
minimum-idle: 10
maximum-pool-size: 50
idle-timeout: 60000
max-lifetime: 900000
pool-name: SpringBootDataSource
auto-commit: true
connection-timeout: 5000
connection-test-query: SELECT 1 FROM DUAL
connection-init-sql: SET NAMES utf8mb4;
```
关于事务的超时机制,可以设置以下参数:
```
spring:
jpa:
properties:
hibernate:
transaction:
default_timeout: 30 # 设置事务超时时间为30秒
```
阅读全文