when i using default Spring Boot datasource that create by DataSourceAutoConfiguration hikari pool is correct and max size is ok but i want create custom datasource to set that @primary .
there are some way to create custom Datasource, one of that is
@Bean @ConfigurationProperties(prefix = "spring.datasource") publicDataSourcedataSource() { return DataSourceBuilder.create().build(); }
datasource: jdbc-url: jdbc:mysql://localhost:3306/ihs?useUnicode=yes&characterEncoding=utf8&useSSL=false username:root password:pass hikari: maximum-pool-size:50
when create datasource by this way max pool size is not set ,after google, i fount that DataSourceBuilder dose not set Hikari prop
2017-08-14 22:51:22.844 DEBUG 31814 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Pool stats (total=10, active=0, idle=50, waiting=0)
Another way for create custom datasource is like this :
@Bean
@Primary @ConfigurationProperties("spring.datasource.hikari") publicDataSourcePropertiesdataSourceProperties() { returnnewDataSourceProperties(); } @Bean @Primary @ConfigurationProperties("spring.datasource.hikari") publicDataSourcedataSource() { returndataSourceProperties().initializeDataSourceBuilder().build(); }
2017-08-14 22:51:22.844 DEBUG 31814 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Pool stats (total=50, active=0, idle=50, waiting=0)