Do not trigger transactional event listener if no transaction is active
This commit fixes the behaviour of not triggering a transactional event listener if no transaction is active. Previously, a transaction boundary was all that was necessary to trigger the listener regardless of the fact there was an active transaction. This commit now prevents `Propagation.NOT_SUPPORTED` and `Propagation.SUPPORTS` without an active transaction to trigger the listener. Closes gh-23276
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -60,7 +60,8 @@ class ApplicationListenerMethodTransactionalAdapter extends ApplicationListenerM
|
||||
|
||||
@Override
|
||||
public void onApplicationEvent(ApplicationEvent event) {
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()) {
|
||||
if (TransactionSynchronizationManager.isSynchronizationActive()
|
||||
&& TransactionSynchronizationManager.isActualTransactionActive()) {
|
||||
TransactionSynchronization transactionSynchronization = createTransactionSynchronization(event);
|
||||
TransactionSynchronizationManager.registerSynchronization(transactionSynchronization);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,9 +28,9 @@ import org.springframework.core.annotation.AliasFor;
|
||||
/**
|
||||
* An {@link EventListener} that is invoked according to a {@link TransactionPhase}.
|
||||
*
|
||||
* <p>If the event is not published within the boundaries of a managed transaction, the
|
||||
* event is discarded unless the {@link #fallbackExecution} flag is explicitly set. If a
|
||||
* transaction is running, the event is processed according to its {@code TransactionPhase}.
|
||||
* <p>If the event is not published within an active transaction, the event is discarded
|
||||
* unless the {@link #fallbackExecution} flag is explicitly set. If a transaction is
|
||||
* running, the event is processed according to its {@code TransactionPhase}.
|
||||
*
|
||||
* <p>Adding {@link org.springframework.core.annotation.Order @Order} to your annotated
|
||||
* method allows you to prioritize that listener amongst other listeners running before
|
||||
|
||||
Reference in New Issue
Block a user