1515 */
1616package org .springframework .modulith .events .support ;
1717
18- import java .lang .reflect .Method ;
1918import java .time .Duration ;
2019import java .util .Collection ;
2120import java .util .List ;
3130import org .springframework .context .ApplicationListener ;
3231import org .springframework .context .PayloadApplicationEvent ;
3332import org .springframework .context .event .AbstractApplicationEventMulticaster ;
34- import org .springframework .context .event .ApplicationEventMulticaster ;
3533import org .springframework .context .event .ApplicationListenerMethodAdapter ;
3634import org .springframework .core .ResolvableType ;
3735import org .springframework .core .annotation .AnnotationAwareOrderComparator ;
4644import org .springframework .modulith .events .core .TargetEventPublication ;
4745import org .springframework .transaction .event .TransactionPhase ;
4846import org .springframework .transaction .event .TransactionalApplicationListener ;
49- import org .springframework .transaction .event .TransactionalEventListener ;
5047import org .springframework .util .Assert ;
51- import org .springframework .util .ReflectionUtils ;
5248
5349/**
5450 * An {@link ApplicationEventMulticaster} to register {@link EventPublication}s in an {@link EventPublicationRegistry}
@@ -65,17 +61,12 @@ public class PersistentApplicationEventMulticaster extends AbstractApplicationEv
6561 implements IncompleteEventPublications , SmartInitializingSingleton {
6662
6763 private static final Logger LOGGER = LoggerFactory .getLogger (PersistentApplicationEventMulticaster .class );
68- private static final Method SUPPORTS_METHOD = ReflectionUtils .findMethod (ApplicationListenerMethodAdapter .class ,
69- "shouldHandle" , ApplicationEvent .class , Object [].class );
64+
7065 static final String REPUBLISH_ON_RESTART = "spring.modulith.republish-outstanding-events-on-restart" ;
7166
7267 private final @ NonNull Supplier <EventPublicationRegistry > registry ;
7368 private final @ NonNull Supplier <Environment > environment ;
7469
75- static {
76- ReflectionUtils .makeAccessible (SUPPORTS_METHOD );
77- }
78-
7970 /**
8071 * Creates a new {@link PersistentApplicationEventMulticaster} for the given {@link EventPublicationRegistry}.
8172 *
@@ -228,18 +219,13 @@ private static Object getEventToPersist(ApplicationEvent event) {
228219 : event ;
229220 }
230221
231- @ SuppressWarnings ("null" )
232222 private static boolean matches (ApplicationEvent event , Object payload , ApplicationListener <?> listener ) {
233223
234224 // Verify general listener matching by eagerly evaluating the condition
235- if (ApplicationListenerMethodAdapter .class .isInstance (listener )) {
225+ if (ApplicationListenerMethodAdapter .class .isInstance (listener )
226+ && !((ApplicationListenerMethodAdapter ) listener ).shouldHandle (event )) {
236227
237- boolean result = (boolean ) ReflectionUtils .invokeMethod (SUPPORTS_METHOD , listener , event ,
238- new Object [] { payload });
239-
240- if (!result ) {
241- return false ;
242- }
228+ return false ;
243229 }
244230
245231 return ConditionalEventListener .class .isInstance (listener )
0 commit comments