diff --git a/spring-beans/src/main/java/org/springframework/beans/factory/NoUniqueBeanDefinitionException.java b/spring-beans/src/main/java/org/springframework/beans/factory/NoUniqueBeanDefinitionException.java index 7db0bae6e12aebbd7007d68523f3ba15e4806aca..6bb4f6dbc053c3523b423333264fd4b6e08a8a30 100644 --- a/spring-beans/src/main/java/org/springframework/beans/factory/NoUniqueBeanDefinitionException.java +++ b/spring-beans/src/main/java/org/springframework/beans/factory/NoUniqueBeanDefinitionException.java @@ -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 beanNamesFound; + /** * Create a new {@code NoUniqueBeanDefinitionException}. @@ -54,6 +56,7 @@ public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionExcepti public NoUniqueBeanDefinitionException(Class type, Collection 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 getBeanNamesFound() { + return this.beanNamesFound; + } + }