Skip to content

Commit 66bab2a

Browse files
committed
Revert "Manage asynchronous EventListener with replies"
This reverts commit bee1b77.
1 parent 5682950 commit 66bab2a

File tree

2 files changed

+1
-36
lines changed

2 files changed

+1
-36
lines changed

spring-context/src/main/java/org/springframework/context/event/ApplicationListenerMethodAdapter.java

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,8 @@
3535
import org.springframework.core.BridgeMethodResolver;
3636
import org.springframework.core.ResolvableType;
3737
import org.springframework.core.annotation.AnnotatedElementUtils;
38-
import org.springframework.core.annotation.AnnotationUtils;
3938
import org.springframework.core.annotation.Order;
4039
import org.springframework.expression.EvaluationContext;
41-
import org.springframework.scheduling.annotation.Async;
4240
import org.springframework.util.Assert;
4341
import org.springframework.util.ObjectUtils;
4442
import org.springframework.util.ReflectionUtils;
@@ -84,7 +82,6 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe
8482

8583

8684
public ApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, Method method) {
87-
validateMethod(method);
8885
this.beanName = beanName;
8986
this.method = method;
9087
this.targetClass = targetClass;
@@ -93,14 +90,6 @@ public ApplicationListenerMethodAdapter(String beanName, Class<?> targetClass, M
9390
this.methodKey = new AnnotatedElementKey(this.method, this.targetClass);
9491
}
9592

96-
private static void validateMethod(Method method) {
97-
if (method.getReturnType() != void.class &&
98-
AnnotationUtils.findAnnotation(method, Async.class) != null) {
99-
throw new IllegalStateException(
100-
"Asynchronous @EventListener method is not allowed to return reply events: " + method);
101-
}
102-
}
103-
10493

10594
/**
10695
* Initialize this instance.

spring-context/src/test/java/org/springframework/context/event/AnnotationDrivenEventListenerTests.java

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -155,19 +155,6 @@ public void methodSignatureNoEvent() {
155155
failingContext.refresh();
156156
}
157157

158-
@Test
159-
public void asyncWithReplyEventListener() {
160-
AnnotationConfigApplicationContext failingContext =
161-
new AnnotationConfigApplicationContext();
162-
failingContext.register(BasicConfiguration.class,
163-
InvalidAsyncEventListener.class);
164-
165-
this.thrown.expect(BeanInitializationException.class);
166-
this.thrown.expectMessage(InvalidAsyncEventListener.class.getName());
167-
this.thrown.expectMessage("asyncCannotUseReply");
168-
failingContext.refresh();
169-
}
170-
171158
@Test
172159
public void simpleReply() {
173160
load(TestEventListener.class, ReplyEventListener.class);
@@ -669,17 +656,6 @@ public void cannotBeCalled(String s, Integer what) {
669656
}
670657
}
671658

672-
@Component
673-
static class InvalidAsyncEventListener {
674-
675-
@EventListener
676-
@Async
677-
public Integer asyncCannotUseReply(String payload) {
678-
return 42;
679-
}
680-
681-
}
682-
683659

684660
@Component
685661
static class ReplyEventListener extends AbstractTestEventListener {
@@ -790,7 +766,6 @@ public void handleAsync(AnotherTestEvent event) {
790766
this.eventCollector.addEvent(this, event);
791767
this.countDownLatch.countDown();
792768
}
793-
794769
}
795770

796771

@@ -894,6 +869,7 @@ public void handleString(GenericEventPojo<String> value) {
894869
}
895870

896871

872+
897873
@EventListener
898874
@Retention(RetentionPolicy.RUNTIME)
899875
public @interface ConditionalEvent {

0 commit comments

Comments
 (0)