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`.

See gh-28712
  • Loading branch information
vpavic authored and snicoll committed Nov 17, 2021
1 parent de172a5 commit c8dd0a5
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 c8dd0a5

Please sign in to comment.