1

I want to use my Spring Boot 2.1 App without any connection pooler (HikariCP in this case) since the default pooler is HikariCP !

How should I go ahead and implement this ?

The use case is I want to use a common db pooler (pgBouncer) for all my application instances and other applications ! I cannot achieve this when each Spring Boot app runs with its own implicit connection pooler(HikariCP).

How should I implement this use case ? Is this a better solution for common database connection pooling ?

Nitish Kumar
  • 721
  • 1
  • 10
  • 26

2 Answers2

0

You can exclude HikariCP through the POM.

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
            <exclusions>
                <exclusion>
                    <artifactId>com.zaxxer</artifactId>
                    <groupId>HikariCP</groupId>
                </exclusion>
            </exclusions>
        </dependency>

Then you can create your own JdbcTemplate using whichever datasource you want. For more information on that, see here Creating custom connection pool in Spring Boot application

aarbor
  • 1,398
  • 1
  • 9
  • 24
0

You can also deactivate it by providing simple driver datasource:

public DataSource datasource() throws SQLException {
    Driver driver = DriverManager.getDriver(url);
    SimpleDriverDataSource dataSource = new SimpleDriverDataSource(driver, url, username, password);
    return dataSource;
}
user3774109
  • 1,978
  • 1
  • 12
  • 13