spring-batch icon indicating copy to clipboard operation
spring-batch copied to clipboard

Regression in AbstractBatchConfiguration for dataSource Autowiring [BATCH-2819]

Open spring-projects-issues opened this issue 6 years ago • 2 comments
trafficstars

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

spring-projects-issues avatar Apr 24 '19 18:04 spring-projects-issues

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.

kimehdgns avatar Feb 03 '20 14:02 kimehdgns

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

df007df avatar Jul 28 '22 12:07 df007df

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().

fmbenhassine avatar Sep 20 '22 10:09 fmbenhassine