Skip to content

Introduce @BatchTransactionManager to make it easier to configure Spring Batch to use a custom transaction manager #37650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nightswimmings opened this issue Oct 2, 2023 · 8 comments
Labels
status: superseded An issue that has been superseded by another

Comments

@nightswimmings
Copy link

nightswimmings commented Oct 2, 2023

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 ?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 2, 2023
@wilkinsona
Copy link
Member

wilkinsona commented Oct 2, 2023

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.

@nightswimmings
Copy link
Author

nightswimmings commented Oct 3, 2023

Thanks Andy! Still, besides my individual issue, I think the default for the transactionmanager should be different if @BatchDatasource is present.

@wilkinsona
Copy link
Member

wilkinsona commented Oct 3, 2023

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.

@wilkinsona wilkinsona added the status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team label Oct 3, 2023
@nightswimmings
Copy link
Author

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

@fmbenhassine
Copy link
Contributor

@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.

@wilkinsona wilkinsona changed the title BatchAutoconfiguration is injecting as default batch TransactionManager the @Primary one in the context Introduce @BatchTranasctionManager to make it easier to configure Spring Batch to use a custom transaction manager Oct 4, 2023
@wilkinsona wilkinsona added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged status: waiting-for-internal-feedback An issue that needs input from a member or another Spring Team labels Oct 4, 2023
@wilkinsona wilkinsona added this to the 3.x milestone Oct 4, 2023
@wilkinsona wilkinsona changed the title Introduce @BatchTranasctionManager to make it easier to configure Spring Batch to use a custom transaction manager Introduce @BatchTransactionManager to make it easier to configure Spring Batch to use a custom transaction manager Oct 4, 2023
BenchmarkingBuffalo added a commit to BenchmarkingBuffalo/spring-boot that referenced this issue Feb 9, 2024
Add a new annotation for marking a second PlatformTransactionManager to be used in batch processing.

See spring-projectsgh-37650
BenchmarkingBuffalo added a commit to BenchmarkingBuffalo/spring-boot that referenced this issue Feb 9, 2024
Add a new annotation for marking a second PlatformTransactionManager to be used in batch processing.

See spring-projectsgh-37650
@scottfrederick
Copy link
Contributor

Closing in favor of #39473

@scottfrederick scottfrederick closed this as not planned Won't fix, can't repro, duplicate, stale Feb 13, 2024
@scottfrederick scottfrederick added status: superseded An issue that has been superseded by another and removed type: enhancement A general enhancement labels Feb 13, 2024
@scottfrederick scottfrederick removed this from the 3.x milestone Feb 13, 2024
@oumaima-Benjouida-nupsol

This comment was marked as off-topic.

@wilkinsona

This comment was marked as resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: superseded An issue that has been superseded by another
Projects
None yet
Development

No branches or pull requests

6 participants