From e5fe6a5de62e251e26152b5319196dd1997925cd Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Thu, 2 Nov 2017 09:58:11 -0500 Subject: [PATCH] Updated DefaultBatchConfigurer to not overwrite when autowiring This commit prevents autowiring from overwriting a value set for the `DataSource` if it has already been set. Resolves BATCH-2636 --- .../annotation/DefaultBatchConfigurer.java | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/DefaultBatchConfigurer.java b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/DefaultBatchConfigurer.java index 468ae0e04..05562a47e 100644 --- a/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/DefaultBatchConfigurer.java +++ b/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/annotation/DefaultBatchConfigurer.java @@ -46,10 +46,22 @@ public class DefaultBatchConfigurer implements BatchConfigurer { private JobLauncher jobLauncher; private JobExplorer jobExplorer; + /** + * Sets the dataSource. If the {@link DataSource} has been set once, all future + * values are passed are ignored (to prevent {@code}@Autowired{@code} from overwriting + * the value). + * + * @param dataSource + */ @Autowired(required = false) public void setDataSource(DataSource dataSource) { - this.dataSource = dataSource; - this.transactionManager = new DataSourceTransactionManager(dataSource); + if(this.dataSource == null) { + this.dataSource = dataSource; + } + + if(this.transactionManager == null) { + this.transactionManager = new DataSourceTransactionManager(this.dataSource); + } } protected DefaultBatchConfigurer() {}