spring-projects / spring-projects/spring-batch
Help users to avoid mismatched DataSource and TransactionManager pairs
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 3k
- Forks
- 2.5k
- Avg merge
- 6d 53m
- Merged PRs (30d)
- 3
Description
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at JdbcJobRepositoryFactoryBean, which the issue identifies as the common configuration point, and trace how the DataSource and transaction manager are supplied by @EnableJdbcJobRepository, JdbcDefaultBatchConfiguration, and Spring Boot's @BatchDataSource and @BatchTransactionManager. Define and test detection of mismatched DataSource instances, with completion marked by an early warning or failure during configuration.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, database
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100