Skip to content

Commit bb05bc7

Browse files
committed
EventListenerMethodProcessor leniently handles unresolvable bean types
Issue: SPR-13712
1 parent 2a3bf69 commit bb05bc7

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,16 @@ public void afterSingletonsInstantiated() {
7575
String[] allBeanNames = this.applicationContext.getBeanNamesForType(Object.class);
7676
for (String beanName : allBeanNames) {
7777
if (!ScopedProxyUtils.isScopedTarget(beanName)) {
78-
Class<?> type = AutoProxyUtils.determineTargetClass(this.applicationContext.getBeanFactory(), beanName);
78+
Class<?> type = null;
79+
try {
80+
type = AutoProxyUtils.determineTargetClass(this.applicationContext.getBeanFactory(), beanName);
81+
}
82+
catch (Throwable ex) {
83+
// An unresolvable bean type, probably from a lazy bean - let's ignore it.
84+
if (logger.isDebugEnabled()) {
85+
logger.debug("Could not resolve target class for bean with name '" + beanName + "'", ex);
86+
}
87+
}
7988
if (type != null) {
8089
if (ScopedObject.class.isAssignableFrom(type)) {
8190
try {
@@ -107,8 +116,7 @@ public void afterSingletonsInstantiated() {
107116
* {@link EventListener} annotated methods.
108117
*/
109118
protected List<EventListenerFactory> getEventListenerFactories() {
110-
Map<String, EventListenerFactory> beans =
111-
this.applicationContext.getBeansOfType(EventListenerFactory.class);
119+
Map<String, EventListenerFactory> beans = this.applicationContext.getBeansOfType(EventListenerFactory.class);
112120
List<EventListenerFactory> allFactories = new ArrayList<EventListenerFactory>(beans.values());
113121
AnnotationAwareOrderComparator.sort(allFactories);
114122
return allFactories;

0 commit comments

Comments
 (0)