org.springframework.beans.factory

## Class NoUniqueBeanDefinitionException

- java.lang.Object
- - java.lang.Throwable
  - - java.lang.Exception
    - - java.lang.RuntimeException
      - - org.springframework.core.NestedRuntimeException
        - - org.springframework.beans.BeansException
          - - org.springframework.beans.factory.NoSuchBeanDefinitionException
            - - org.springframework.beans.factory.NoUniqueBeanDefinitionException

- All Implemented Interfaces:
    Serializable

      public class NoUniqueBeanDefinitionException
      extends NoSuchBeanDefinitionException

  Exception thrown when a `BeanFactory` is asked for a bean instance for which multiple matching candidates have been found when only one matching bean was expected.
  Since:
    3.2.1
  Author:
    Juergen Hoeller
  See Also:
    `BeanFactory.getBean(Class)`, Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `NoUniqueBeanDefinitionException(Class<?> type, Collection<String> beanNamesFound)` Create a new `NoUniqueBeanDefinitionException`.
    `NoUniqueBeanDefinitionException(Class<?> type, int numberOfBeansFound, String message)` Create a new `NoUniqueBeanDefinitionException`.
    `NoUniqueBeanDefinitionException(Class<?> type, String... beanNamesFound)` Create a new `NoUniqueBeanDefinitionException`.
    `NoUniqueBeanDefinitionException(ResolvableType type, Collection<String> beanNamesFound)` Create a new `NoUniqueBeanDefinitionException`.
    `NoUniqueBeanDefinitionException(ResolvableType type, String... beanNamesFound)` Create a new `NoUniqueBeanDefinitionException`.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `Collection<String>` | `getBeanNamesFound()` Return the names of all beans found when only one matching bean was expected.
    `int` | `getNumberOfBeansFound()` Return the number of beans found when only one matching bean was expected.

    - ### Methods inherited from class org.springframework.beans.factory.NoSuchBeanDefinitionException

      `getBeanName, getBeanType, getResolvableType`

    - ### Methods inherited from class org.springframework.core.NestedRuntimeException

      `contains, getMessage, getMostSpecificCause, getRootCause`

    - ### Methods inherited from class java.lang.Throwable

      `addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### NoUniqueBeanDefinitionException

          public NoUniqueBeanDefinitionException(Class<?> type,
                                                 int numberOfBeansFound,
                                                 String message)

      Create a new `NoUniqueBeanDefinitionException`.
      Parameters:
        `type` - required type of the non-unique bean
        `numberOfBeansFound` - the number of matching beans
        `message` - detailed message describing the problem

    - #### NoUniqueBeanDefinitionException

          public NoUniqueBeanDefinitionException(Class<?> type,
                                                 Collection<String> beanNamesFound)

      Create a new `NoUniqueBeanDefinitionException`.
      Parameters:
        `type` - required type of the non-unique bean
        `beanNamesFound` - the names of all matching beans (as a Collection)

    - #### NoUniqueBeanDefinitionException

          public NoUniqueBeanDefinitionException(Class<?> type,
                                                 String... beanNamesFound)

      Create a new `NoUniqueBeanDefinitionException`.
      Parameters:
        `type` - required type of the non-unique bean
        `beanNamesFound` - the names of all matching beans (as an array)

    - #### NoUniqueBeanDefinitionException

          public NoUniqueBeanDefinitionException(ResolvableType type,
                                                 Collection<String> beanNamesFound)

      Create a new `NoUniqueBeanDefinitionException`.
      Parameters:
        `type` - required type of the non-unique bean
        `beanNamesFound` - the names of all matching beans (as a Collection)
      Since:
        5.1

    - #### NoUniqueBeanDefinitionException

          public NoUniqueBeanDefinitionException(ResolvableType type,
                                                 String... beanNamesFound)

      Create a new `NoUniqueBeanDefinitionException`.
      Parameters:
        `type` - required type of the non-unique bean
        `beanNamesFound` - the names of all matching beans (as an array)
      Since:
        5.1

  - ### Method Detail

    - #### getNumberOfBeansFound

          public int getNumberOfBeansFound()

      Return the number of beans found when only one matching bean was expected. For a NoUniqueBeanDefinitionException, this will usually be higher than 1.
      Overrides:
        `getNumberOfBeansFound` in class `NoSuchBeanDefinitionException`
      See Also:
        `NoSuchBeanDefinitionException.getBeanType()`

    - #### getBeanNamesFound

          @Nullable
          public Collection<String> getBeanNamesFound()

      Return the names of all beans found when only one matching bean was expected. Note that this may be `null` if not specified at construction time.
      Since:
        4.3
      See Also:
        `NoSuchBeanDefinitionException.getBeanType()`