EventListenerMethodProcessor does not validate target classes behind proxies anymore

Issue: SPR-13526
Issue: SPR-13538
This commit is contained in:
Juergen Hoeller
2015-10-07 13:25:14 +02:00
parent 28c07a6d38
commit dbec2121a0
2 changed files with 45 additions and 78 deletions

View File

@@ -73,6 +73,7 @@ public class AnnotationDrivenEventListenerTests {
private CountDownLatch countDownLatch; // 1 call by default
@After
public void closeContext() {
if (this.context != null) {
@@ -80,6 +81,7 @@ public class AnnotationDrivenEventListenerTests {
}
}
@Test
public void simpleEventJavaConfig() {
load(TestEventListener.class);
@@ -241,13 +243,6 @@ public class AnnotationDrivenEventListenerTests {
this.eventCollector.assertTotalEventsCount(1);
}
@Test
public void methodNotAvailableOnProxyIsDetected() throws Exception {
thrown.expect(BeanInitializationException.class);
thrown.expectMessage("handleIt2");
load(InvalidProxyTestBean.class);
}
@Test
public void eventListenerWorksWithCglibProxy() throws Exception {
load(CglibProxyTestBean.class);
@@ -409,6 +404,7 @@ public class AnnotationDrivenEventListenerTests {
assertThat(listener.order, contains("first", "second", "third"));
}
private void load(Class<?>... classes) {
List<Class<?>> allClasses = new ArrayList<>();
allClasses.add(BasicConfiguration.class);
@@ -450,6 +446,7 @@ public class AnnotationDrivenEventListenerTests {
}
static abstract class AbstractTestEventListener extends AbstractIdentifiable {
@Autowired
@@ -458,9 +455,9 @@ public class AnnotationDrivenEventListenerTests {
protected void collectEvent(Object content) {
this.eventCollector.addEvent(this, content);
}
}
@Component
static class TestEventListener extends AbstractTestEventListener {
@@ -473,15 +470,16 @@ public class AnnotationDrivenEventListenerTests {
public void handleString(String content) {
collectEvent(content);
}
}
@EventListener
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@interface FooListener {
}
@Component
static class MetaAnnotationListenerTestBean extends AbstractTestEventListener {
@@ -491,6 +489,7 @@ public class AnnotationDrivenEventListenerTests {
}
}
@Component
static class ContextEventListener extends AbstractTestEventListener {
@@ -501,6 +500,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Component
static class InvalidMethodSignatureEventListener {
@@ -509,6 +509,7 @@ public class AnnotationDrivenEventListenerTests {
}
}
@Component
static class ReplyEventListener extends AbstractTestEventListener {
@@ -532,6 +533,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Component
static class ExceptionEventListener extends AbstractTestEventListener {
@@ -557,12 +559,14 @@ public class AnnotationDrivenEventListenerTests {
}
}
@Configuration
@Import(BasicConfiguration.class)
@EnableAsync(proxyTargetClass = true)
static class AsyncConfiguration {
}
@Component
static class AsyncEventListener extends AbstractTestEventListener {
@@ -578,6 +582,7 @@ public class AnnotationDrivenEventListenerTests {
}
}
interface SimpleService extends Identifiable {
@EventListener
@@ -585,6 +590,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Component
@Scope(proxyMode = ScopedProxyMode.INTERFACES)
static class ProxyTestBean extends AbstractIdentifiable implements SimpleService {
@@ -598,14 +604,6 @@ public class AnnotationDrivenEventListenerTests {
}
}
@Component
@Scope(proxyMode = ScopedProxyMode.INTERFACES)
static class InvalidProxyTestBean extends ProxyTestBean {
@EventListener // does not exist on any interface so it should fail
public void handleIt2(TestEvent event) {
}
}
@Component
@Scope(proxyMode = ScopedProxyMode.TARGET_CLASS)
@@ -617,6 +615,7 @@ public class AnnotationDrivenEventListenerTests {
}
}
@Component
static class GenericEventListener extends AbstractTestEventListener {
@@ -626,6 +625,7 @@ public class AnnotationDrivenEventListenerTests {
}
}
@Component
static class ConditionalEventListener extends TestEventListener {
@@ -648,6 +648,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Component
static class OrderedTestListener extends TestEventListener {