-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
GH-3733 Configure TxManager for DefLockRepository #3782
Conversation
Fixes spring-projects#3733 The `@Transactional` resolves a primary `TransactionManager` bean from the application context which might not be sufficient for all the use-case. To make it work with the custom (or specific) `TransactionManager` we have to extend a `DefaultLockRepository` and override all those `@Transactional` method * Change the logic of the `DefaultLockRepository` from `@Transactional` to the `TransactionTemplate` and use provided `TransactionManager` or resolve one from the application context * Adjust tests to use explicit `TransactionManager` and call `afterSingletonsInstantiated()` to initialize a default `TransactionTemplate` * Mention the change in the docs
@Override | ||
public void afterSingletonsInstantiated() { | ||
if (this.transactionManager == null) { | ||
this.transactionManager = this.applicationContext.getBean(PlatformTransactionManager.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe try/catch with a friendly message to indicate if there is not one unique TM in the context, the registry needs one to be passed in?
DefaultTransactionDefinition transactionDefinition = | ||
new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW); | ||
transactionDefinition.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE); | ||
return new TransactionTemplate(this.transactionManager, transactionDefinition) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we store this template in a field too?
} | ||
DefaultTransactionDefinition transactionDefinition = | ||
new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRES_NEW); | ||
transactionDefinition.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not a field?
* Add `BeanInitializationException` for no-unique `PlatformTransactionManager` bean in the `afterSingletonsInstantiated()`
...tion-jdbc/src/main/java/org/springframework/integration/jdbc/lock/DefaultLockRepository.java
Outdated
Show resolved
Hide resolved
Co-authored-by: Gary Russell <grussell@vmware.com>
Fixes #3733
The
@Transactional
resolves a primaryTransactionManager
beanfrom the application context which might not be sufficient for all
the use-case.
To make it work with the custom (or specific)
TransactionManager
we have to extend a
DefaultLockRepository
and override all those@Transactional
methodDefaultLockRepository
from@Transactional
to the
TransactionTemplate
and use providedTransactionManager
or resolve one from the application context
TransactionManager
and callafterSingletonsInstantiated()
to initialize a defaultTransactionTemplate