Same as BatchAutconfiguration uses @BatchDatasource to tell apart the batch datasource from the main domain one, it should happen something similar to TransactionManager, or either build it by default over the passed @BatchDatasource
I would be tempted to think this is a batch issue in https://github.com/spring-projects/spring-batch/blob/11e653287f51a3c495a836cc0646ee58daea9fbf/spring-batch-core/src/main/java/org/springframework/batch/core/configuration/support/DefaultBatchConfiguration.java, but I can understand they don't want to provide defaults, but just expect the superior level to do so
Another option is some kind of Atomikos or old ChainedTransactionManager chaining
Is there any workaround right now in latest Boot to configure an independent Batch stack (transactionmanager,emf,datasource) on a regular Boot service that already expects an autoconfigured conventional domain database ?
Comment From: wilkinsona
Is there any workaround right now in latest Boot to configure an independent Batch stack
You can provide your own sub-class of DefaultBatchConfiguration. That will make Boot's auto-configuration back off, allowing you to configure Batch with the DataSource and TransactionManager that meet your needs.
Comment From: nightswimmings
Thanks Andy! Still, besides my individual issue, I think the default for the transactionmanager should be different if @BatchDatasource is present.
Comment From: wilkinsona
WDYT, @fmbenhassine? Should we introduce @BatchTransactionManager alongside the existing @BatchDataSource? We decided not to do so last year but I'm not opposed to the idea. It would make it easier for users to configure Batch with a custom DB and transaction manager, removing the need for them to extends DefaultBatchConfiguration.
Comment From: nightswimmings
Or perhaps autoconfigure the TransactionManager according to a possible @BatchDatasource like DefaultBatchConfigurer did.
if(getTransactionManager() == null) {
logger.warn("No transaction manager was provided, using a DataSourceTransactionManager");
this.transactionManager = new DataSourceTransactionManager(this.dataSource);
}
also
if(dataSource == null) {
logger.warn("No datasource was provided...using a Map based JobRepository");
if(getTransactionManager() == null) {
logger.warn("No transaction manager was provided, using a ResourcelessTransactionManager");
this.transactionManager = new ResourcelessTransactionManager();
}
What we almost certain don't want ever is using the context/domain TransacionManager if you are takeing the trouble of defining a @BatchDatasource, IMO
Comment From: fmbenhassine
@wilkinsona I am not opposed to adding @BatchTransactionManager neither. IIRC from our last discussion, the concern was how to make sure the datasource and transaction manager are aligned. But if the Boot defaults ensure that and the docs clearly mention what is expected from the user with regard to that alignment when overriding the defaults, then this new annotation would indeed make the configuration of Batch more straightforward.
Comment From: scottfrederick
Closing in favor of #39473
Comment From: oumaima-Benjouida-nupsol
Hello, i was trying to configure and connect multiple databases in my spring app, which means I had also to configure multiple transactions manager depending on the data source config, now when I do the same for spring batch as follows: @Bean(name = "batchTransactionManager") public PlatformTransactionManager batchTransactionManager() { return new DataSourceTransactionManager(nupsolDataSource()); } it doesn't initialize any transaction bean
Comment From: wilkinsona
@oumaima-Benjouida-nupsol please ask questions on Stack Overflow. Also, please note that your comment isn't really related to this issue as it's about @BatchTransactionManager which, judging by the code snippet above, you're not using.