我是springboot和JPA世界的新手。我的应用程序出现问题,maximum-pool-size
没有更新。始终为10。为什么总是采用默认值?
下面是我的application.yml
spring:
profiles: uat
datasource:
platform: oracle
initialization-mode: never
driverClassName: xxx.xx.xx
url: xxx
username: xxx
password: xxx
hikari.connection-timeout: 20000
hikari.minimum-idle: 5
hikari.maximum-pool-size: 15
hikari.idle-timeout: 300000
hikari.max-lifetime: 1200000
我添加了hikari.maximumPoolSize: 100
,但输出仍然相同10
下面是配置Bean。
@EnableJpaRepositories( basePackages = {
"entityjar.XX", "com.XXX"}, repositoryFactoryBeanClass = EnversRevisionRepositoryFactoryBean.class )
@EnableTransactionManagement
@EnableEncryptableProperties
public class DatabaseConfig
{
@Autowired
private Environment env;
@Bean
@Primary
@ConfigurationProperties( "spring.datasource" )
public DataSourcePropertie
s dataSourceProperties()
{
return new DataSourceProperties();
}
@Bean( name = "dataSource", destroyMethod = "close" )
public DataSource dataSource()
{
String usr = env.getProperty( "spring.datasource.username" );
String pwd = env.getProperty( "spring.datasource.password" );
usr = StringUtils.isNotBlank( usr ) ? usr : getValueFromCredStash( "datasource.username" );
pwd = StringUtils.isNotBlank( pwd ) ? pwd : getValueFromCredStash( "datasource.password" );
String url = env.getProperty( "spring.datasource.url" );
final DataSourceBuilder factory = DataSourceBuilder.create().username( usr ).password( pwd )
.url( url );
final DataSource dsc = factory.build();
return dsc;
}
[com.zaxxer.hikari.HikariConfig] > HikariPool-1 - configuration:
[] DEBUG [com.zaxxer.hikari.HikariConfig] > allowPoolSuspension.............false
[] DEBUG [com.zaxxer.hikari.HikariConfig] > autoCommit......................true
[] DEBUG [com.zaxxer.hikari.HikariConfig] > catalog.........................none
[] DEBUG [com.zaxxer.hikari.HikariConfig] > connectionInitSql...............none
[] DEBUG [com.zaxxer.hikari.HikariConfig] > connectionTestQuery.............none
[] DEBUG [com.zaxxer.hikari.HikariConfig] > connectionTimeout...............30000
[] DEBUG [com.zaxxer.hikari.HikariConfig] > dataSource......................none
[] DEBUG [com.zaxxer.hikari.HikariConfig] > dataSourceClassName.............none
[] DEBUG [com.zaxxer.hikari.HikariConfig] > dataSourceJNDI..................none
[] DEBUG [com.zaxxer.hikari.HikariConfig] > dataSourceProperties............{password=<masked>}
[] DEBUG [com.zaxxer.hikari.HikariConfig] > driverClassName................."oracle.jdbc.OracleDriver"
[] DEBUG [com.zaxxer.hikari.HikariConfig] > healthCheckProperties...........{}
[] DEBUG [com.zaxxer.hikari.HikariConfig] > healthCheckRegistry.............none
[] DEBUG [com.zaxxer.hikari.HikariConfig] > idleTimeout.....................600000
[] DEBUG [com.zaxxer.hikari.HikariConfig] > initializationFailFast..........true
[] DEBUG [com.zaxxer.hikari.HikariConfig] > initializationFailTimeout.......1
[] DEBUG [com.zaxxer.hikari.HikariConfig] > isolateInternalQueries..........false
[] DEBUG [com.zaxxer.hikari.HikariConfig] > jdbc4ConnectionTest.............false
[] DEBUG [com.zaxxer.hikari.HikariConfig] > jdbcUrl.........................jdbc:oracle:thin:@XX
[] DEBUG [com.zaxxer.hikari.HikariConfig] > leakDetectionThreshold..........0
[] DEBUG [com.zaxxer.hikari.HikariConfig] > maxLifetime.....................1800000
[] DEBUG [com.zaxxer.hikari.HikariConfig] > maximumPoolSize.................10
[] DEBUG [com.zaxxer.hikari.HikariConfig] > metricRegistry..................none
[] DEBUG [com.zaxxer.hikari.HikariConfig] > metricsTrackerFactory...........none
[] DEBUG [com.zaxxer.hikari.HikariConfig] > minimumIdle.....................10
[] DEBUG [com.zaxxer.hikari.HikariConfig] > password........................<masked>
[] DEBUG [com.zaxxer.hikari.HikariConfig] > poolName........................"HikariPool-1"
[] DEBUG [com.zaxxer.hikari.HikariConfig] > readOnly........................false
[] DEBUG [com.zaxxer.hikari.HikariConfig] > registerMbeans..................false
[] DEBUG [com.zaxxer.hikari.HikariConfig] > scheduledExecutor...............none
[] DEBUG [com.zaxxer.hikari.HikariConfig] > scheduledExecutorService........internal
[] DEBUG [com.zaxxer.hikari.HikariConfig] > schema..........................none
[] DEBUG [com.zaxxer.hikari.HikariConfig] > threadFactory...................internal
[] DEBUG [com.zaxxer.hikari.HikariConfig] > transactionIsolation............default
[] DEBUG [com.zaxxer.hikari.HikariConfig] > username........................xxx
[] DEBUG [com.zaxxer.hikari.HikariConfig] > validationTimeout...............5000
[] INFO [com.zaxxer.hikari.HikariDataSource] > HikariPool-1 - Starting...
您可以使用Spring Boot中提供的这些属性:
spring.datasource.hikari.minimumIdle=5
spring.datasource.hikari.maximumPoolSize=8
然后:
spring.datasource.hikari.idleTimeout=120000
为了限制空闲连接的寿命,但是hikari没有为您提供初始连接数的此类属性。
您必须将minimum-idle更改为minimumIdle,并将maximum-pool-size更改为maximumPoolSize
如果是application.yaml
hikari:
minimumIdle: 10
maximumPoolSize: 20
connectionTimeout: 50000
leak-detection-threshold: 45000