Skip to content

Commit c9b6f0d

Browse files
committed
Fix "Configure Two DataSources" example
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`.
1 parent f01d086 commit c9b6f0d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Diff for: spring-boot-project/spring-boot-docs/src/main/java/org/springframework/boot/docs/howto/dataaccess/configuretwodatasources/MyCompleteDataSourcesConfiguration.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import com.zaxxer.hikari.HikariDataSource;
2020
import org.apache.commons.dbcp2.BasicDataSource;
2121

22+
import org.springframework.beans.factory.annotation.Qualifier;
2223
import org.springframework.boot.autoconfigure.jdbc.DataSourceProperties;
2324
import org.springframework.boot.context.properties.ConfigurationProperties;
2425
import org.springframework.context.annotation.Bean;
@@ -50,7 +51,8 @@ public DataSourceProperties secondDataSourceProperties() {
5051

5152
@Bean
5253
@ConfigurationProperties("app.datasource.second.configuration")
53-
public BasicDataSource secondDataSource(DataSourceProperties secondDataSourceProperties) {
54+
public BasicDataSource secondDataSource(
55+
@Qualifier("secondDataSourceProperties") DataSourceProperties secondDataSourceProperties) {
5456
return secondDataSourceProperties.initializeDataSourceBuilder().type(BasicDataSource.class).build();
5557
}
5658

0 commit comments

Comments
 (0)