Vladimir Safonov
Vladimir Safonov

Reputation: 67

Liquibase pool setting spring boot

I surprisingly discovered that liquibase creates his own connection pool with default values and therefore holds 10 connections to db. It doesn't use connection pool configured from application.properties. So, I have a couple of questions:

  1. What is necessity of own pool?
  2. How can I configure this pool?

Upvotes: 1

Views: 1598

Answers (1)

amseager
amseager

Reputation: 6391

The linked question has indeed a correct answer. But obviously, 10 connections are taken from the default settings of Hikari Pool (it is the default db connection pool starting from Spring Boot 2.0).

So, here is the modified version of the same configuration but with Hikari instead of tomcat-jdbc:

    @LiquibaseDataSource
    @Bean
    public DataSource liquibaseDataSource() {
        DataSource ds = DataSourceBuilder.create()
                .username(liquibaseDataSourceProperties.getUser())
                .password(liquibaseDataSourceProperties.getPassword())
                .url(liquibaseDataSourceProperties.getUrl())
                .driverClassName(liquibaseDataSourceProperties.getDriver())
                .build();
        if (ds instanceof HikariDataSource) {
            ((HikariDataSource) ds).setMaximumPoolSize(2); //10 by default
        }
        return ds;
    }

Upvotes: 1

Related Questions