Skip to content

Commit 2a2e557

Browse files
committed
GH-372 - Propagate original exception from CompletionRegisteringAdvisor.
We now propagate potentially occurring exceptions in CompletionRegisteringAdvisor to make sure the standard exception handling facilities kick in, both for synchronous and asynchronous listener invocations.
1 parent 1acd2fd commit 2a2e557

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/support/CompletionRegisteringAdvisor.java

+3-4
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.aopalliance.intercept.MethodInvocation;
2424
import org.slf4j.Logger;
2525
import org.slf4j.LoggerFactory;
26-
import org.springframework.aop.Advisor;
2726
import org.springframework.aop.MethodMatcher;
2827
import org.springframework.aop.Pointcut;
2928
import org.springframework.aop.support.AbstractPointcutAdvisor;
@@ -41,8 +40,8 @@
4140
import org.springframework.util.ConcurrentLruCache;
4241

4342
/**
44-
* An {@link Advisor} to decorate {@link TransactionalEventListener} annotated methods to mark the previously registered
45-
* event publications as completed on successful method execution.
43+
* An {@link org.springframework.aop.Advisor} to decorate {@link TransactionalEventListener} annotated methods to mark
44+
* the previously registered event publications as completed on successful method execution.
4645
*
4746
* @author Oliver Drotbohm
4847
*/
@@ -177,7 +176,7 @@ public Object invoke(MethodInvocation invocation) throws Throwable {
177176
method, o_O.getMessage());
178177
}
179178

180-
return result;
179+
throw o_O;
181180
}
182181

183182
// Mark publication complete if the method is a transactional event listener.

spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/support/PersistentApplicationEventMulticaster.java

+7-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import org.springframework.context.ApplicationListener;
3030
import org.springframework.context.PayloadApplicationEvent;
3131
import org.springframework.context.event.AbstractApplicationEventMulticaster;
32-
import org.springframework.context.event.ApplicationEventMulticaster;
3332
import org.springframework.context.event.ApplicationListenerMethodAdapter;
3433
import org.springframework.core.ResolvableType;
3534
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
@@ -41,7 +40,6 @@
4140
import org.springframework.modulith.events.core.PublicationTargetIdentifier;
4241
import org.springframework.transaction.event.TransactionPhase;
4342
import org.springframework.transaction.event.TransactionalApplicationListener;
44-
import org.springframework.transaction.event.TransactionalEventListener;
4543
import org.springframework.util.Assert;
4644
import org.springframework.util.ReflectionUtils;
4745

@@ -174,7 +172,13 @@ private void invokeTargetListener(EventPublication publication) {
174172
private ApplicationListener<ApplicationEvent> executeListenerWithCompletion(EventPublication publication,
175173
TransactionalApplicationListener<ApplicationEvent> listener) {
176174

177-
listener.processEvent(publication.getApplicationEvent());
175+
try {
176+
listener.processEvent(publication.getApplicationEvent());
177+
} catch (Exception o_O) {
178+
if (LOGGER.isErrorEnabled()) {
179+
LOGGER.error("Error republishing event publication " + publication, o_O);
180+
}
181+
}
178182

179183
return listener;
180184
}

0 commit comments

Comments
 (0)