Browse Source

EventListenerMethodProcessor defensively handles unresolvable method signatures

Issue: SPR-14330
pull/1073/head
Juergen Hoeller 10 years ago
parent
commit
f657952cee
  1. 26
      spring-context/src/main/java/org/springframework/context/event/EventListenerMethodProcessor.java

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

@ -42,6 +42,7 @@ import org.springframework.core.MethodIntrospector;
import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotatedElementUtils;
import org.springframework.core.annotation.AnnotationAwareOrderComparator; import org.springframework.core.annotation.AnnotationAwareOrderComparator;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
/** /**
* Register {@link EventListener} annotated method as individual {@link ApplicationListener} * Register {@link EventListener} annotated method as individual {@link ApplicationListener}
@ -125,14 +126,23 @@ public class EventListenerMethodProcessor implements SmartInitializingSingleton,
protected void processBean(final List<EventListenerFactory> factories, final String beanName, final Class<?> targetType) { protected void processBean(final List<EventListenerFactory> factories, final String beanName, final Class<?> targetType) {
if (!this.nonAnnotatedClasses.contains(targetType)) { if (!this.nonAnnotatedClasses.contains(targetType)) {
Map<Method, EventListener> annotatedMethods = MethodIntrospector.selectMethods(targetType, Map<Method, EventListener> annotatedMethods = null;
new MethodIntrospector.MetadataLookup<EventListener>() { try {
@Override annotatedMethods = MethodIntrospector.selectMethods(targetType,
public EventListener inspect(Method method) { new MethodIntrospector.MetadataLookup<EventListener>() {
return AnnotatedElementUtils.findMergedAnnotation(method, EventListener.class); @Override
} public EventListener inspect(Method method) {
}); return AnnotatedElementUtils.findMergedAnnotation(method, EventListener.class);
if (annotatedMethods.isEmpty()) { }
});
}
catch (Throwable ex) {
// An unresolvable type in a method signature, probably from a lazy bean - let's ignore it.
if (logger.isDebugEnabled()) {
logger.debug("Could not resolve methods for bean with name '" + beanName + "'", ex);
}
}
if (CollectionUtils.isEmpty(annotatedMethods)) {
this.nonAnnotatedClasses.add(targetType); this.nonAnnotatedClasses.add(targetType);
if (logger.isTraceEnabled()) { if (logger.isTraceEnabled()) {
logger.trace("No @EventListener annotations found on bean class: " + targetType); logger.trace("No @EventListener annotations found on bean class: " + targetType);

Loading…
Cancel
Save