Revised NoSuchBeanDefinitionException message for proper array class names

Issue: SPR-14595
This commit is contained in:
Juergen Hoeller 2016-08-17 17:13:28 +02:00
parent 4b06b60007
commit 022b013563
2 changed files with 7 additions and 5 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2016 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -17,6 +17,7 @@
package org.springframework.beans.factory; package org.springframework.beans.factory;
import org.springframework.beans.BeansException; import org.springframework.beans.BeansException;
import org.springframework.util.ClassUtils;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
@ -74,7 +75,7 @@ public class NoSuchBeanDefinitionException extends BeansException {
* @param message detailed message describing the problem * @param message detailed message describing the problem
*/ */
public NoSuchBeanDefinitionException(Class<?> type, String message) { public NoSuchBeanDefinitionException(Class<?> type, String message) {
super("No qualifying bean of type [" + type.getName() + "] is defined: " + message); super("No qualifying bean of type [" + ClassUtils.getQualifiedName(type) + "] is defined: " + message);
this.beanType = type; this.beanType = type;
} }
@ -85,7 +86,8 @@ public class NoSuchBeanDefinitionException extends BeansException {
* @param message detailed message describing the problem * @param message detailed message describing the problem
*/ */
public NoSuchBeanDefinitionException(Class<?> type, String dependencyDescription, String message) { public NoSuchBeanDefinitionException(Class<?> type, String dependencyDescription, String message) {
super("No qualifying bean of type [" + type.getName() + "] found for dependency" + super("No qualifying bean" + (!StringUtils.hasLength(dependencyDescription) ?
" of type [" + ClassUtils.getQualifiedName(type) + "]" : "") + " found for dependency" +
(StringUtils.hasLength(dependencyDescription) ? " [" + dependencyDescription + "]" : "") + (StringUtils.hasLength(dependencyDescription) ? " [" + dependencyDescription + "]" : "") +
": " + message); ": " + message);
this.beanType = type; this.beanType = type;

View File

@ -1420,7 +1420,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
checkBeanNotOfRequiredType(type, descriptor); checkBeanNotOfRequiredType(type, descriptor);
throw new NoSuchBeanDefinitionException(type, dependencyDescription, throw new NoSuchBeanDefinitionException(type, dependencyDescription,
"expected at least 1 bean which qualifies as autowire candidate for this dependency. " + "expected at least 1 bean which qualifies as autowire candidate. " +
"Dependency annotations: " + ObjectUtils.nullSafeToString(descriptor.getAnnotations())); "Dependency annotations: " + ObjectUtils.nullSafeToString(descriptor.getAnnotations()));
} }
@ -1667,7 +1667,7 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
sources.add(factoryMethod); sources.add(factoryMethod);
} }
Class<?> targetType = beanDefinition.getTargetType(); Class<?> targetType = beanDefinition.getTargetType();
if (targetType != null && !targetType.equals(obj.getClass())) { if (targetType != null && targetType != obj.getClass()) {
sources.add(targetType); sources.add(targetType);
} }
return sources.toArray(new Object[sources.size()]); return sources.toArray(new Object[sources.size()]);