Expected Behavior
When using its JDBC support, Batch should do what it can to protect against someone misconfiguring the DataSource and TransactionManager. If Batch can identify that its DataSource is not the same as its TransactionManager's DataSource, it should log a warning or even fail fast when starting up.
Current Behavior
The misconfiguration is ignored.
Context
I'd like an arrangement like this to fail or at least log a warning:
@EnableBatchProcessing
@EnableJdbcJobRepository(dataSourceRef = "firstDataSource")
public class BrokenTransactionConfigurationApplication {
private final DataSource firstDataSource = new EmbeddedDatabaseBuilder().build();
private final DataSource secondDataSource = new EmbeddedDatabaseBuilder().build();
@Bean
DataSource firstDataSource() {
return new EmbeddedDatabaseBuilder().build();
}
@Bean
DataSource secondDataSource() {
return new EmbeddedDatabaseBuilder().build();
}
@Bean
DataSourceTransactionManager firstTransactionManager() {
return new DataSourceTransactionManager(this.firstDataSource);
}
@Bean
DataSourceTransactionManager transactionManager() {
return new DataSourceTransactionManager(this.secondDataSource);
}
public static void main(String[] args) {
SpringApplication.run(BrokenTransactionConfigurationApplication.class, args);
}
}
You could also get into a similar state by sub-classing JdbcDefaultBatchConfiguration and overriding getDataSource() and/or getTransactionManager(). For Spring Boot users, @BatchDataSource and @BatchTransactionManager are another way.
I think all these approaches end up configuring a JdbcJobRepositoryFactoryBean. Hopefully that provides a central place where some validation of the configured DataSource and TransactionManager could be done to catch misconfigurations early and irrespective of how they arose.
Expected Behavior
When using its JDBC support, Batch should do what it can to protect against someone misconfiguring the
DataSourceandTransactionManager. If Batch can identify that itsDataSourceis not the same as itsTransactionManager'sDataSource, it should log a warning or even fail fast when starting up.Current Behavior
The misconfiguration is ignored.
Context
I'd like an arrangement like this to fail or at least log a warning:
You could also get into a similar state by sub-classing
JdbcDefaultBatchConfigurationand overridinggetDataSource()and/orgetTransactionManager(). For Spring Boot users,@BatchDataSourceand@BatchTransactionManagerare another way.I think all these approaches end up configuring a
JdbcJobRepositoryFactoryBean. Hopefully that provides a central place where some validation of the configuredDataSourceandTransactionManagercould be done to catch misconfigurations early and irrespective of how they arose.