YazanLpizra
YazanLpizra

Reputation: 540

Spring Boot 2: How to configure HikariCP using application.properties file

I am relatively new to Spring and Spring Boot but I can't seem to find a guide on how to create an app using Spring Boot, Flyway, and Spring Boot JPA that will actually run on my machine. I always end up with the same issue:

Error creating bean with name 'flywayInitializer' defined in class path resource [org/springframework/boot/autoconfigure/flyway/FlywayAutoConfiguration$FlywayConfiguration.class]: Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: dataSource or dataSourceClassName or jdbcUrl is required.

I am trying to fully configure HikariCP through the application.properties file, but I can't seem to find a way. Any help is extremely appriciated.

My full stack trace and relevant Java code and application.properties files are in this gist:

https://gist.github.com/anonymous/cb309a836ddae36f5e401697f763dde5

Upvotes: 3

Views: 5626

Answers (2)

Francis Huang
Francis Huang

Reputation: 550

You can update application.properties to use

spring.datasource.jdbc-url=...
datasource.flyway.jdbc-url=...

instead of

.url=

I'm also following the Pluralsight course Building Your First Spring Boot Application

I found the answer in another StackOverflow post. Spring Boot 2 changes the default JDBC connection pool from Tomcat to HikariCP for performance improvements. HikariCP expects different properties.

In the tutorial, multiple data sources are optional which is why it works when you remove PersistenceConfiguration.java

Upvotes: 1

Strelok
Strelok

Reputation: 51491

Remove PersistenceConfiguration class it’s not required. Spring Boot autoconfigures the data sources for you and flyway to use.

HikariCP is now the default pool implementation in spring boot 2.

Also remove all the data source related properties from application.properties except spring.datasource.url.

Upvotes: 2

Related Questions