forked from spring-projects/spring-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduced NoUniqueBeanDefinitionException as a dedicated subclass of…
… NoSuchBeanDefinitionException Issue: SPR-10194
- Loading branch information
Showing
8 changed files
with
163 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...eans/src/main/java/org/springframework/beans/factory/NoUniqueBeanDefinitionException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Copyright 2002-2013 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. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.springframework.beans.factory; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
|
||
import org.springframework.util.StringUtils; | ||
|
||
/** | ||
* Exception thrown when a {@code BeanFactory} is asked for a bean instance for which | ||
* multiple matching candidates have been found when only one matching bean was expected. | ||
* | ||
* @author Juergen Hoeller | ||
* @since 3.2.1 | ||
* @see BeanFactory#getBean(Class) | ||
*/ | ||
@SuppressWarnings("serial") | ||
public class NoUniqueBeanDefinitionException extends NoSuchBeanDefinitionException { | ||
|
||
private int numberOfBeansFound; | ||
|
||
|
||
/** | ||
* Create a new {@code NoUniqueBeanDefinitionException}. | ||
* @param type required type of the non-unique bean | ||
* @param numberOfBeansFound the number of matching beans | ||
* @param message detailed message describing the problem | ||
*/ | ||
public NoUniqueBeanDefinitionException(Class<?> type, int numberOfBeansFound, String message) { | ||
super(type, message); | ||
this.numberOfBeansFound = numberOfBeansFound; | ||
} | ||
|
||
/** | ||
* Create a new {@code NoUniqueBeanDefinitionException}. | ||
* @param type required type of the non-unique bean | ||
* @param beanNamesFound the names of all matching beans (as a Collection) | ||
*/ | ||
public NoUniqueBeanDefinitionException(Class<?> type, Collection<String> beanNamesFound) { | ||
this(type, beanNamesFound.size(), "expected single matching bean but found " + beanNamesFound.size() + ": " + | ||
StringUtils.collectionToCommaDelimitedString(beanNamesFound)); | ||
} | ||
|
||
/** | ||
* Create a new {@code NoUniqueBeanDefinitionException}. | ||
* @param type required type of the non-unique bean | ||
* @param beanNamesFound the names of all matching beans (as an array) | ||
*/ | ||
public NoUniqueBeanDefinitionException(Class<?> type, String... beanNamesFound) { | ||
this(type, Arrays.asList(beanNamesFound)); | ||
} | ||
|
||
|
||
/** | ||
* Return the number of beans found when only one matching bean was expected. | ||
* For a NoUniqueBeanDefinitionException, this will usually be higher than 1. | ||
* @see #getBeanType() | ||
*/ | ||
@Override | ||
public int getNumberOfBeansFound() { | ||
return this.numberOfBeansFound; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.