Skip to content

Commit c65b0a1

Browse files
committed
Merge branch '6.0.x'
# Conflicts: # spring-tx/src/main/java/org/springframework/transaction/event/TransactionalApplicationListenerMethodAdapter.java
2 parents 1e73439 + d781f29 commit c65b0a1

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

spring-tx/src/main/java/org/springframework/transaction/event/TransactionalApplicationListenerMethodAdapter.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,10 @@
4747
public class TransactionalApplicationListenerMethodAdapter extends ApplicationListenerMethodAdapter
4848
implements TransactionalApplicationListener<ApplicationEvent> {
4949

50-
private final TransactionalEventListener annotation;
51-
5250
private final TransactionPhase transactionPhase;
5351

52+
private final boolean fallbackExecution;
53+
5454
private final List<SynchronizationCallback> callbacks = new CopyOnWriteArrayList<>();
5555

5656

@@ -63,12 +63,12 @@ public class TransactionalApplicationListenerMethodAdapter extends ApplicationLi
6363
public TransactionalApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method) {
6464
super(beanName, targetClass, method);
6565
TransactionalEventListener eventAnn =
66-
AnnotatedElementUtils.findMergedAnnotation(method, TransactionalEventListener.class);
66+
AnnotatedElementUtils.findMergedAnnotation(getTargetMethod(), TransactionalEventListener.class);
6767
if (eventAnn == null) {
6868
throw new IllegalStateException("No TransactionalEventListener annotation found on method: " + method);
6969
}
70-
this.annotation = eventAnn;
7170
this.transactionPhase = eventAnn.phase();
71+
this.fallbackExecution = eventAnn.fallbackExecution();
7272
}
7373

7474

@@ -91,8 +91,8 @@ public void onApplicationEvent(ApplicationEvent event) {
9191
logger.debug("Registered transaction synchronization for " + event);
9292
}
9393
}
94-
else if (this.annotation.fallbackExecution()) {
95-
if (this.annotation.phase() == TransactionPhase.AFTER_ROLLBACK && logger.isWarnEnabled()) {
94+
else if (this.fallbackExecution) {
95+
if (getTransactionPhase() == TransactionPhase.AFTER_ROLLBACK && logger.isWarnEnabled()) {
9696
logger.warn("Processing " + event + " as a fallback execution on AFTER_ROLLBACK phase");
9797
}
9898
processEvent(event);

spring-tx/src/test/java/org/springframework/transaction/event/TransactionalEventListenerTests.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ public void afterCommitWithTransactionalComponentListenerProxiedViaDynamicProxy(
158158
getEventCollector().assertNoEventReceived();
159159
}
160160

161+
@Test
162+
public void afterCommitWithTransactionalComponentListenerWithInterfaceProxy() {
163+
load(TransactionalComponentTestListenerWithInterface.class);
164+
this.transactionTemplate.execute(status -> {
165+
getContext().publishEvent("SKIP");
166+
getEventCollector().assertNoEventReceived();
167+
return null;
168+
});
169+
getEventCollector().assertNoEventReceived();
170+
}
171+
161172
@Test
162173
public void afterRollback() {
163174
load(AfterCompletionExplicitTestListener.class);
@@ -552,6 +563,25 @@ public void handleAfterCommit(String data) {
552563
}
553564

554565

566+
interface TransactionalComponentTestInterface {
567+
568+
void handleAfterCommit(String data);
569+
}
570+
571+
572+
@Transactional
573+
@Component
574+
static class TransactionalComponentTestListenerWithInterface extends BaseTransactionalTestListener implements
575+
TransactionalComponentTestInterface {
576+
577+
@TransactionalEventListener(condition = "!'SKIP'.equals(#data)")
578+
@Override
579+
public void handleAfterCommit(String data) {
580+
handleEvent(EventCollector.AFTER_COMMIT, data);
581+
}
582+
}
583+
584+
555585
@Component
556586
static class BeforeCommitTestListener extends BaseTransactionalTestListener {
557587

0 commit comments

Comments
 (0)