here is the following code for configuring several datasources in a spring batch project
@Configuration
@RequiredArgsConstructor
public class DatasourceConfiguration {
private final Environment env;
@Bean(name = "batchDataSource")
@ConfigurationProperties(prefix = "spring.batch-datasource")
public DataSource primaryDataSource() {
return DataSourceBuilder.create().build();
}
@Bean(name = "customersDataSource")
@ConfigurationProperties(prefix = "spring.customers-datasource")
public DataSource secondaryDataSource() {
return DataSourceBuilder.create().build();
}
@Bean
BatchConfigurer configurer(@Qualifier("batchDataSource") DataSource dataSource) {
return new DefaultBatchConfigurer(dataSource);
}
}
when loading the app I get the following error:
Field dataSource in org.springframework.batch.core.configuration.annotation.AbstractBatchConfiguration required a single bean, but 2 were found:
- batchDataSource: defined by method 'primaryDataSource' in class path resource [com/comp/lr/snapshot/customers/job/config/DatasourceConfiguration.class]
- customersDataSource: defined by method 'secondaryDataSource' in class path resource [com/comp/lr/snapshot/customers/job/config/DatasourceConfiguration.class]
But why is it happening if I'm using @Qaulifier annotation?