How to use HikariCP in Spring Boot with two datasources in conjunction with Flyway

Declaring your own DataSource will already have implicity disabled Spring Boot’s auto-configuration of a data source. In other words this won’t be having any effect:

@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})

I think the problem lies in the fact that you aren’t binding Hikari-specific configuration to your MySQL DataSource. You need to do something like this:

@Bean
@Primary
@ConfigurationProperties("spring.datasource.hikari")
public DataSource mySQLDataSource() {
    return mySQLDataSourceProperties().initializeDataSourceBuilder().build();
}

This will mean that your mySQLDataSourceProperties are configured with general-purpose data source configuration. They then create a HikariDataSource which is further configured with the Hikari-specific configuration.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)