NoUniqueBeanDefinitionException exposes beanNamesFound collection

Issue: SPR-13968
This commit is contained in:
Juergen Hoeller 2016-03-11 12:49:57 +01:00
parent 68f6cf9d3a
commit b6f69492a3
1 changed files with 14 additions and 1 deletions

View File

@ -1,5 +1,5 @@
/*
* 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;
}
}