sneijder10
sneijder10

Reputation: 47

Set hikari pool size for custom DataSource

I want to change Hikari pool size for my custom DataSource, I use Spring boot 2+ version.

I can set dataSource url,dataSource password etc. I wrote values to application.properties file.After that I read these values with environment.getproperty and set dataSource but I donot know same process for pool size:(

Upvotes: 2

Views: 9789

Answers (2)

Ming M Zheng
Ming M Zheng

Reputation: 304

I am assuming you custom your dataSource by set your DataSource bean. then you can create custom hikariconfig as follow, remember to replace hard code values below with values in your environment.getproperty:

    @Bean
    public DataSource getDataSource() {

        HikariConfig config = new HikariConfig();
        config.setJdbcUrl("jdbc:mysql://yourhostname:port/dbname");
        config.setDriverClassName("com.mysql.jdbc.Driver");
        config.setUsername("dbUsername");
        config.setPassword("dbPassword");
        config.setMinimumIdle(10);
        config.setMaximumPoolSize(10);
        config.setConnectionTimeout(1500);
        //you can set more config here

        return new HikariDataSource(config);
    }

Upvotes: 4

Ori Marko
Ori Marko

Reputation: 58862

Hikari prefix is spring.datasource.hikari.

You can set maximum pool size as 10:

 spring.datasource.hikari.maximumPoolSize=10

spring.datasource.hikari.*= # Hikari specific settings

It will automatically set your pool size

Upvotes: 0

Related Questions