Skip to content

Commit 022b013

Browse files
committed
Revised NoSuchBeanDefinitionException message for proper array class names
Issue: SPR-14595
1 parent 4b06b60 commit 022b013

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

spring-beans/src/main/java/org/springframework/beans/factory/NoSuchBeanDefinitionException.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 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.
@@ -17,6 +17,7 @@
1717
package org.springframework.beans.factory;
1818

1919
import org.springframework.beans.BeansException;
20+
import org.springframework.util.ClassUtils;
2021
import org.springframework.util.StringUtils;
2122

2223
/**
@@ -74,7 +75,7 @@ public NoSuchBeanDefinitionException(Class<?> type) {
7475
* @param message detailed message describing the problem
7576
*/
7677
public NoSuchBeanDefinitionException(Class<?> type, String message) {
77-
super("No qualifying bean of type [" + type.getName() + "] is defined: " + message);
78+
super("No qualifying bean of type [" + ClassUtils.getQualifiedName(type) + "] is defined: " + message);
7879
this.beanType = type;
7980
}
8081

@@ -85,7 +86,8 @@ public NoSuchBeanDefinitionException(Class<?> type, String message) {
8586
* @param message detailed message describing the problem
8687
*/
8788
public NoSuchBeanDefinitionException(Class<?> type, String dependencyDescription, String message) {
88-
super("No qualifying bean of type [" + type.getName() + "] found for dependency" +
89+
super("No qualifying bean" + (!StringUtils.hasLength(dependencyDescription) ?
90+
" of type [" + ClassUtils.getQualifiedName(type) + "]" : "") + " found for dependency" +
8991
(StringUtils.hasLength(dependencyDescription) ? " [" + dependencyDescription + "]" : "") +
9092
": " + message);
9193
this.beanType = type;

spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1420,7 +1420,7 @@ private void raiseNoMatchingBeanFound(
14201420
checkBeanNotOfRequiredType(type, descriptor);
14211421

14221422
throw new NoSuchBeanDefinitionException(type, dependencyDescription,
1423-
"expected at least 1 bean which qualifies as autowire candidate for this dependency. " +
1423+
"expected at least 1 bean which qualifies as autowire candidate. " +
14241424
"Dependency annotations: " + ObjectUtils.nullSafeToString(descriptor.getAnnotations()));
14251425
}
14261426

@@ -1667,7 +1667,7 @@ public Object getOrderSource(Object obj) {
16671667
sources.add(factoryMethod);
16681668
}
16691669
Class<?> targetType = beanDefinition.getTargetType();
1670-
if (targetType != null && !targetType.equals(obj.getClass())) {
1670+
if (targetType != null && targetType != obj.getClass()) {
16711671
sources.add(targetType);
16721672
}
16731673
return sources.toArray(new Object[sources.size()]);

0 commit comments

Comments
 (0)