Skip to content

Overriding transaction management [BATCH-2294] #1289

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
spring-projects-issues opened this issue Aug 14, 2014 · 4 comments
Closed

Overriding transaction management [BATCH-2294] #1289

spring-projects-issues opened this issue Aug 14, 2014 · 4 comments
Labels
has: backports Legacy label from JIRA. Superseded by "for: backport-to-x.x.x" in: core type: bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

Abhay opened BATCH-2294 and commented

SimpleBatchConfiguration which gets loaded by any of spring application, created transactionManager bean irrespective of whether that bean is already created or not. This results in overriding transaction manager

@ConditionalOnMissingBean could be used for resolution of this issues


Affects: 3.0.1

Reference URL: http://stackoverflow.com/q/25303163/3073323

Issue Links:

  • BATCH-2642 Document how to make Spring Batch work with Spring Data JPA repositories
    ("is depended on by")

Referenced from: pull request #609, and commits a68d700

Backported to: 4.1.0.M3

3 votes, 5 watchers

@spring-projects-issues
Copy link
Collaborator Author

Michael Minella commented

Can you please provide your configuration?

@spring-projects-issues
Copy link
Collaborator Author

Thiago B. Negri commented

I'm facing the same issue.

As a workaround I've defined the exact same transaction manager I already have defined in other configuration class in my Spring Batch configuration class. So my application starts defining my transaction manager, then gets overridden by Spring Batch transaction manager and then gets overridden by my second definition of the transaction manager.

Sweet.

Adding a @ConditionalOnMissingBean seems to be easy enough. Am I missing something? Why isn't this addressed already? It's open since 2014.

@spring-projects-issues
Copy link
Collaborator Author

Martin Meyer commented

I'm not sure what this magic @ConditionalOnMissingBean annotation is (I can't find Javadoc for it in Spring Framework or Spring Batch), but I've created a PR to try to address this issue:

#609

 

Basically I just try to autowire a transaction manager and make a new one only if there isn't one.

@spring-projects-issues
Copy link
Collaborator Author

Mahmoud Ben Hassine commented

This issue is resolved with #634.

In order to provide a custom transaction manager, a custom BatchConfigurer must be provided. For example:

@Bean
 public BatchConfigurer batchConfigurer() {
 	return new DefaultBatchConfigurer() {
 		@Override
 		public PlatformTransactionManager getTransactionManager() {
 			return new MyTransactionManager();
 		}
 	};
 }

Documentation was updated accordingly (See https://github.com/spring-projects/spring-batch/pull/620/files).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
has: backports Legacy label from JIRA. Superseded by "for: backport-to-x.x.x" in: core type: bug
Projects
None yet
Development

No branches or pull requests

1 participant