From 2241ae19600c57d37f60d13da95d2d08f57f07b8 Mon Sep 17 00:00:00 2001 From: Oliver Drotbohm Date: Fri, 20 Oct 2023 16:44:19 +0200 Subject: [PATCH] GH-329 - Upgrade to Spring Boot 3.2 RC1. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove workaround of calling ApplicationListenerMethodAdapter.shouldHandle(…) reflectively. --- pom.xml | 2 +- ...PersistentApplicationEventMulticaster.java | 22 ++++--------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index 18dad691..5ba69df3 100644 --- a/pom.xml +++ b/pom.xml @@ -41,7 +41,7 @@ UTF-8 UTF-8 6.0.12 - 3.2.0-M3 + 3.2.0-RC1 diff --git a/spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/support/PersistentApplicationEventMulticaster.java b/spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/support/PersistentApplicationEventMulticaster.java index f4c157d1..afb27270 100644 --- a/spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/support/PersistentApplicationEventMulticaster.java +++ b/spring-modulith-events/spring-modulith-events-core/src/main/java/org/springframework/modulith/events/support/PersistentApplicationEventMulticaster.java @@ -15,7 +15,6 @@ */ package org.springframework.modulith.events.support; -import java.lang.reflect.Method; import java.time.Duration; import java.util.Collection; import java.util.List; @@ -31,7 +30,6 @@ import org.springframework.context.ApplicationEvent; import org.springframework.context.ApplicationListener; import org.springframework.context.PayloadApplicationEvent; import org.springframework.context.event.AbstractApplicationEventMulticaster; -import org.springframework.context.event.ApplicationEventMulticaster; import org.springframework.context.event.ApplicationListenerMethodAdapter; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotationAwareOrderComparator; @@ -46,9 +44,7 @@ import org.springframework.modulith.events.core.PublicationTargetIdentifier; import org.springframework.modulith.events.core.TargetEventPublication; import org.springframework.transaction.event.TransactionPhase; import org.springframework.transaction.event.TransactionalApplicationListener; -import org.springframework.transaction.event.TransactionalEventListener; import org.springframework.util.Assert; -import org.springframework.util.ReflectionUtils; /** * An {@link ApplicationEventMulticaster} to register {@link EventPublication}s in an {@link EventPublicationRegistry} @@ -65,17 +61,12 @@ public class PersistentApplicationEventMulticaster extends AbstractApplicationEv implements IncompleteEventPublications, SmartInitializingSingleton { private static final Logger LOGGER = LoggerFactory.getLogger(PersistentApplicationEventMulticaster.class); - private static final Method SUPPORTS_METHOD = ReflectionUtils.findMethod(ApplicationListenerMethodAdapter.class, - "shouldHandle", ApplicationEvent.class, Object[].class); + static final String REPUBLISH_ON_RESTART = "spring.modulith.republish-outstanding-events-on-restart"; private final @NonNull Supplier registry; private final @NonNull Supplier environment; - static { - ReflectionUtils.makeAccessible(SUPPORTS_METHOD); - } - /** * Creates a new {@link PersistentApplicationEventMulticaster} for the given {@link EventPublicationRegistry}. * @@ -228,18 +219,13 @@ public class PersistentApplicationEventMulticaster extends AbstractApplicationEv : event; } - @SuppressWarnings("null") private static boolean matches(ApplicationEvent event, Object payload, ApplicationListener listener) { // Verify general listener matching by eagerly evaluating the condition - if (ApplicationListenerMethodAdapter.class.isInstance(listener)) { + if (ApplicationListenerMethodAdapter.class.isInstance(listener) + && !((ApplicationListenerMethodAdapter) listener).shouldHandle(event)) { - boolean result = (boolean) ReflectionUtils.invokeMethod(SUPPORTS_METHOD, listener, event, - new Object[] { payload }); - - if (!result) { - return false; - } + return false; } return ConditionalEventListener.class.isInstance(listener)