spring-batch
spring-batch copied to clipboard
Regression in AbstractBatchConfiguration for dataSource Autowiring [BATCH-2819]
Jean-Francois Larouche opened BATCH-2819 and commented
Hi,
This commit:
https://github.com/spring-projects/spring-batch/commit/7a9a2a9c50c0e1f7b103dd8e81e283e3503a85bb#diff-03a06349c3e7d9dcf99d6433a1d565db
When providing our own BatchConfigurer and wiring up the DastaSource correctly, this add a regression when none of the dataSource bean are @Primary. Because the SimpleBatchConfigurer is always created.
Would it not have been possible to iterate through the Collection inside getConfigurer(...) and just use the DataSource that have a @Primary in the list instead? This would have caused 0 regression.
Thanks.
New Error:
Field dataSource in org.springframework.batch.core.configuration.annotation.AbstractBatchConfiguration required a single bean, but 2 were found:Field dataSource in org.springframework.batch.core.configuration.annotation.AbstractBatchConfiguration required a single bean, but 2 were found: - batchDataSource: defined by method 'batchDataSource' in class path resource [com/sepaq/batch/config/DataSourceBatchConfig.class] - oracleDataSource: defined by method 'oracleDataSource' in class path resource [com/sepaq/batch/jpa/datasource/DataSourceOracleConfig.class]
Affects: 4.1.1, 4.1.2
I think that commit forces @Primary annotation to be used or need bean with name "dataSource" in multiple datasource configurations. Even if I use in-memory job repository.
I had the same problem, and here's how I configured it. I want the specific dataSource can be specified.
Whether the dataSource can be injected to BatchConfigurer.
Because we are now using DefaultBatchConfigurer(dataSource) to inject the specific used.
Affects: 4.3.6
This is superseded by #3942 . The data source to use for Batch meta-data can be provided either declaratively as an attribute of @EnableBatchProcessing, or programmatically by overriding DefaultBatchConfiguration#getDataSource().