Skip to content

Commit 2fd691b

Browse files
committed
EventListenerMethodProcessor defensively handles unresolvable method signatures
Issue: SPR-14330 (cherry picked from commit f657952)
1 parent d467dc2 commit 2fd691b

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

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

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -41,6 +41,7 @@
4141
import org.springframework.core.annotation.AnnotationAwareOrderComparator;
4242
import org.springframework.core.annotation.AnnotationUtils;
4343
import org.springframework.util.Assert;
44+
import org.springframework.util.CollectionUtils;
4445

4546
/**
4647
* Register {@link EventListener} annotated method as individual {@link ApplicationListener}
@@ -124,14 +125,23 @@ protected List<EventListenerFactory> getEventListenerFactories() {
124125

125126
protected void processBean(final List<EventListenerFactory> factories, final String beanName, final Class<?> targetType) {
126127
if (!this.nonAnnotatedClasses.contains(targetType)) {
127-
Map<Method, EventListener> annotatedMethods = MethodIntrospector.selectMethods(targetType,
128-
new MethodIntrospector.MetadataLookup<EventListener>() {
129-
@Override
130-
public EventListener inspect(Method method) {
131-
return AnnotationUtils.findAnnotation(method, EventListener.class);
132-
}
133-
});
134-
if (annotatedMethods.isEmpty()) {
128+
Map<Method, EventListener> annotatedMethods = null;
129+
try {
130+
annotatedMethods = MethodIntrospector.selectMethods(targetType,
131+
new MethodIntrospector.MetadataLookup<EventListener>() {
132+
@Override
133+
public EventListener inspect(Method method) {
134+
return AnnotationUtils.findAnnotation(method, EventListener.class);
135+
}
136+
});
137+
}
138+
catch (Throwable ex) {
139+
// An unresolvable type in a method signature, probably from a lazy bean - let's ignore it.
140+
if (logger.isDebugEnabled()) {
141+
logger.debug("Could not resolve methods for bean with name '" + beanName + "'", ex);
142+
}
143+
}
144+
if (CollectionUtils.isEmpty(annotatedMethods)) {
135145
this.nonAnnotatedClasses.add(targetType);
136146
if (logger.isTraceEnabled()) {
137147
logger.trace("No @EventListener annotations found on bean class: " + targetType);

0 commit comments

Comments
 (0)