diff --git a/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java b/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java index fc1416fdaa..a57eb0c612 100644 --- a/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java +++ b/spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java @@ -35,10 +35,8 @@ import org.springframework.context.expression.AnnotatedElementKey; import org.springframework.core.BridgeMethodResolver; import org.springframework.core.ResolvableType; import org.springframework.core.annotation.AnnotatedElementUtils; -import org.springframework.core.annotation.AnnotationUtils; import org.springframework.core.annotation.Order; import org.springframework.expression.EvaluationContext; -import org.springframework.scheduling.annotation.Async; import org.springframework.util.Assert; import org.springframework.util.ObjectUtils; import org.springframework.util.ReflectionUtils; @@ -84,7 +82,6 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe public ApplicationListenerMethodAdapter(String beanName, Class targetClass, Method method) { - validateMethod(method); this.beanName = beanName; this.method = method; this.targetClass = targetClass; @@ -93,14 +90,6 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe this.methodKey = new AnnotatedElementKey(this.method, this.targetClass); } - private static void validateMethod(Method method) { - if (method.getReturnType() != void.class && - AnnotationUtils.findAnnotation(method, Async.class) != null) { - throw new IllegalStateException( - "Asynchronous @EventListener method is not allowed to return reply events: " + method); - } - } - /** * Initialize this instance. diff --git a/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java b/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java index ca8d8ae376..89738660ad 100644 --- a/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java +++ b/spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java @@ -155,19 +155,6 @@ public class AnnotationDrivenEventListenerTests { failingContext.refresh(); } - @Test - public void asyncWithReplyEventListener() { - AnnotationConfigApplicationContext failingContext = - new AnnotationConfigApplicationContext(); - failingContext.register(BasicConfiguration.class, - InvalidAsyncEventListener.class); - - this.thrown.expect(BeanInitializationException.class); - this.thrown.expectMessage(InvalidAsyncEventListener.class.getName()); - this.thrown.expectMessage("asyncCannotUseReply"); - failingContext.refresh(); - } - @Test public void simpleReply() { load(TestEventListener.class, ReplyEventListener.class); @@ -669,17 +656,6 @@ public class AnnotationDrivenEventListenerTests { } } - @Component - static class InvalidAsyncEventListener { - - @EventListener - @Async - public Integer asyncCannotUseReply(String payload) { - return 42; - } - - } - @Component static class ReplyEventListener extends AbstractTestEventListener { @@ -790,7 +766,6 @@ public class AnnotationDrivenEventListenerTests { this.eventCollector.addEvent(this, event); this.countDownLatch.countDown(); } - } @@ -894,6 +869,7 @@ public class AnnotationDrivenEventListenerTests { } + @EventListener @Retention(RetentionPolicy.RUNTIME) public @interface ConditionalEvent {