|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2015 the original author or authors. |
| 2 | + * Copyright 2002-2016 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
41 | 41 | import org.springframework.core.annotation.AnnotationAwareOrderComparator;
|
42 | 42 | import org.springframework.core.annotation.AnnotationUtils;
|
43 | 43 | import org.springframework.util.Assert;
|
| 44 | +import org.springframework.util.CollectionUtils; |
44 | 45 |
|
45 | 46 | /**
|
46 | 47 | * Register {@link EventListener} annotated method as individual {@link ApplicationListener}
|
@@ -124,14 +125,23 @@ protected List<EventListenerFactory> getEventListenerFactories() {
|
124 | 125 |
|
125 | 126 | protected void processBean(final List<EventListenerFactory> factories, final String beanName, final Class<?> targetType) {
|
126 | 127 | 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)) { |
135 | 145 | this.nonAnnotatedClasses.add(targetType);
|
136 | 146 | if (logger.isTraceEnabled()) {
|
137 | 147 | logger.trace("No @EventListener annotations found on bean class: " + targetType);
|
|
0 commit comments