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
This commit is contained in:
Michael Minella
2017-11-02 09:58:11 -05:00
parent 70a5ec24c5
commit e5fe6a5de6

View File

@@ -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() {}