|
42 | 42 | import org.springframework.core.annotation.AnnotatedElementUtils;
|
43 | 43 | import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
44 | 44 | import org.springframework.util.Assert;
|
| 45 | +import org.springframework.util.CollectionUtils; |
45 | 46 |
|
46 | 47 | /**
|
47 | 48 | * Register {@link EventListener} annotated method as individual {@link ApplicationListener}
|
@@ -125,14 +126,23 @@ protected List<EventListenerFactory> getEventListenerFactories() {
|
125 | 126 |
|
126 | 127 | protected void processBean(final List<EventListenerFactory> factories, final String beanName, final Class<?> targetType) {
|
127 | 128 | if (!this.nonAnnotatedClasses.contains(targetType)) {
|
128 |
| - Map<Method, EventListener> annotatedMethods = MethodIntrospector.selectMethods(targetType, |
129 |
| - new MethodIntrospector.MetadataLookup<EventListener>() { |
130 |
| - @Override |
131 |
| - public EventListener inspect(Method method) { |
132 |
| - return AnnotatedElementUtils.findMergedAnnotation(method, EventListener.class); |
133 |
| - } |
134 |
| - }); |
135 |
| - if (annotatedMethods.isEmpty()) { |
| 129 | + Map<Method, EventListener> annotatedMethods = null; |
| 130 | + try { |
| 131 | + annotatedMethods = MethodIntrospector.selectMethods(targetType, |
| 132 | + new MethodIntrospector.MetadataLookup<EventListener>() { |
| 133 | + @Override |
| 134 | + public EventListener inspect(Method method) { |
| 135 | + return AnnotatedElementUtils.findMergedAnnotation(method, EventListener.class); |
| 136 | + } |
| 137 | + }); |
| 138 | + } |
| 139 | + catch (Throwable ex) { |
| 140 | + // An unresolvable type in a method signature, probably from a lazy bean - let's ignore it. |
| 141 | + if (logger.isDebugEnabled()) { |
| 142 | + logger.debug("Could not resolve methods for bean with name '" + beanName + "'", ex); |
| 143 | + } |
| 144 | + } |
| 145 | + if (CollectionUtils.isEmpty(annotatedMethods)) { |
136 | 146 | this.nonAnnotatedClasses.add(targetType);
|
137 | 147 | if (logger.isTraceEnabled()) {
|
138 | 148 | logger.trace("No @EventListener annotations found on bean class: " + targetType);
|
|
0 commit comments