HikariCP 连接池配置:
http://stackoverflow.com/questions/29650501/hikaricp-starts-when-mvn-spring-bootrun-but-not-with-a-deployable-war-file
spring.datasource.validation-query=SELECT 1 spring.datasource.max-active=10 spring.datasource.max-idle=8 spring.datasource.min-idle=8 spring.datasource.initial-size=5 spring.datasource.test-on-borrow=true spring.datasource.test-on-return=true
spring.datasource.url=jdbc:mysql://localhost:3306/myDb spring.datasource.driverClassName=com.mysql.jdbc.Driver
@Configuration
class DataSourceConfig { @Value('${spring.datasource.username}') private String user; @Value('${spring.datasource.password}') private String password; @Value('${spring.datasource.url}') private String dataSourceUrl; @Value('${spring.datasource.dataSourceClassName}') private String dataSourceClassName; @Value('${spring.datasource.connectionTimeout}') private int connectionTimeout; @Value('${spring.datasource.maxLifetime}') private int maxLifetime; @Bean public DataSource primaryDataSource() { Properties dsProps = [url: dataSourceUrl, user: user, password: password] Properties configProps = [ connectionTestQuery: 'select 1 from dual', connectionTimeout: connectionTimeout, dataSourceClassName: dataSourceClassName, dataSourceProperties: dsProps, maxLifetime: maxLifetime ] // A default max pool size of 10 seems reasonable for now, so no need to configure for now. HikariConfig hc = new HikariConfig(configProps) HikariDataSource ds = new HikariDataSource(hc) ds } }
https://www.cnblogs.com/fangyuan303687320/category/847518.html