Skip to content

Commit

Permalink
Fix "Configure Two DataSources" example
Browse files Browse the repository at this point in the history
With the present example, the `secondDataSource` bean factory method will use `firstDataSourceProperties` due to it being annotated with `@Primary`.

This commit adds the `@Qualifier` needed to ensure `secondDataSource` bean factory method uses `secondDataSourceProperties`.
  • Loading branch information
vpavic committed Nov 16, 2021
1 parent f1991d8 commit 0856616
Showing 1 changed file with 3 additions and 1 deletion.
Expand Up @@ -19,6 +19,7 @@
import com.zaxxer.hikari.HikariDataSource;
import org.apache.commons.dbcp2.BasicDataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
Expand Down Expand Up @@ -50,7 +51,8 @@ public DataSourceProperties secondDataSourceProperties() {

@Bean
@ConfigurationProperties("app.datasource.second.configuration")
public BasicDataSource secondDataSource(DataSourceProperties secondDataSourceProperties) {
public BasicDataSource secondDataSource(
@Qualifier("secondDataSourceProperties") DataSourceProperties secondDataSourceProperties) {
return secondDataSourceProperties.initializeDataSourceBuilder().type(BasicDataSource.class).build();
}

Expand Down

0 comments on commit 0856616

Please sign in to comment.