Spring Boot Hikari configuration

DDovzhenko :

I'm configuring HikariCP for Spring Boot application, the database is Postgresql.

The documentation says: "We recommended using dataSourceClassName instead of jdbcUrl, but either is acceptable."

However, the next line says: "Note: Spring Boot auto-configuration users, you need to use jdbcUrl-based configuration."

If we use jdbcUrl-based configuration and specify dataSourceClassName then jdbcUrl will be ignored, if we don't specify data source - HikariDataSource will be created. So they recommend using HikariDataSource for Spring Boot apps.

If we use dataSourceClassName - it will be created with given properties (in my case it is PGSimpleDataSource with its ancestor BaseDataSource).

Both these configurations work for me.

So, my questions are:

  1. What is the difference between HikariDataSource and PGSimpleDataSource (or any other recommended)?
  2. Why it is recommended to use jdbcUrl-based configuration (and thus HikariDataSource) in Spring Boot?
Dario Seidl :
  1. HikariCP is a connection pool, and a very good one. We've been using it in several projects in production and it's fast and just works.

  2. If you want to use HikariCP you use HikariDataSource. Spring Boot has started to use it as a default and recommends it (for the same reasons: it's fast and solid).

If you just use the default configuration with spring.datasource.url, it will use HikariCP and should work out-of-the-box.

However, when you manually configure your datasource(s), there is a small issue with Spring Boot 2 and HikariCP. HikariCP expects jdbcUrl or dataSourceClassName, but the Spring Boot configuration property uses url. See the documentation or this question for that.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=134405&siteId=1