3 回答
TA贡献1834条经验 获得超8个赞
@Configuration
@ConfigurationProperties(prefix = "params.datasource")
public class JpaConfig extends HikariConfig {
@Bean
public DataSource dataSource() throws SQLException {
return new HikariDataSource(this);
}
}
application.yml
params:
datasource:
driverClassName: com.mysql.jdbc.Driver
jdbcUrl: jdbc:mysql://localhost:3306/myDb
username: login
password: password
maximumPoolSize: 5
更新!从Spring Boot 1.3.0版本开始:
只需将HikariCP添加到依赖项
配置application.yml
application.yml
spring:
datasource:
type: com.zaxxer.hikari.HikariDataSource
url: jdbc:h2:mem:TEST
driver-class-name: org.h2.Driver
username: username
password: password
hikari:
idle-timeout: 10000
更新!从Spring Boot 2.0.0版本开始:
默认连接池已从Tomcat更改为Hikari :)
添加回答
举报