提交 b6f69492 编写于 作者: J Juergen Hoeller

NoUniqueBeanDefinitionException exposes beanNamesFound collection

Issue: SPR-13968
上级 68f6cf9d
/*
* Copyright 2002-2013 the original author or authors.
* Copyright 2002-2016 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
......@@ -34,6 +34,8 @@ public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionExcepti
private int numberOfBeansFound;
private Collection<String> beanNamesFound;
/**
* Create a new {@code NoUniqueBeanDefinitionException}.
......@@ -54,6 +56,7 @@ public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionExcepti
public NoUniqueBeanDefinitionException(Class<?> type, Collection<String> beanNamesFound) {
this(type, beanNamesFound.size(), "expected single matching bean but found " + beanNamesFound.size() + ": " +
StringUtils.collectionToCommaDelimitedString(beanNamesFound));
this.beanNamesFound = beanNamesFound;
}
/**
......@@ -76,4 +79,14 @@ public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionExcepti
return this.numberOfBeansFound;
}
/**
* Return the names of all beans found when only one matching bean was expected.
* Note that this may be {@code null} if not specified at construction time.
* @since 4.3
* @see #getBeanType()
*/
public Collection<String> getBeanNamesFound() {
return this.beanNamesFound;
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册