org.springframework.beans.factory

## Class NoSuchBeanDefinitionException

- 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

All Implemented Interfaces:
  Serializable

Direct Known Subclasses:
  NoUniqueBeanDefinitionException

    public class NoSuchBeanDefinitionException
    extends BeansException

Exception thrown when a `BeanFactory` is asked for a bean instance for which it cannot find a definition.

Author:
  Rod Johnson, Juergen Hoeller
See Also:
  `BeanFactory.getBean(String)`, `BeanFactory.getBean(Class)`, Serialized Form

### Constructor Summary

Constructors
Constructor and Description
`NoSuchBeanDefinitionException(Class<?> type)` Create a new `NoSuchBeanDefinitionException`.
`NoSuchBeanDefinitionException(Class<?> type, String message)` Create a new `NoSuchBeanDefinitionException`.
`NoSuchBeanDefinitionException(Class<?> type, String dependencyDescription, String message)` Create a new `NoSuchBeanDefinitionException`.
`NoSuchBeanDefinitionException(String name)` Create a new `NoSuchBeanDefinitionException`.
`NoSuchBeanDefinitionException(String name, String message)` Create a new `NoSuchBeanDefinitionException`.

### Method Summary

Methods
`String` `getBeanName()` Return the name of the missing bean, if it was a lookup by name that failed.
`Class<?>` `getBeanType()` Return the required type of the missing bean, if it was a lookup by type that failed.
`int` `getNumberOfBeansFound()` Return the number of beans found when only one matching bean was expected.

### Methods inherited from class org.springframework.beans.BeansException

`equals, hashCode`

### 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, finalize, getClass, notify, notifyAll, wait, wait, wait`

### Constructor Detail

#### NoSuchBeanDefinitionException

    public NoSuchBeanDefinitionException(String name)

Create a new `NoSuchBeanDefinitionException`.

Parameters:
  `name` - the name of the missing bean

#### NoSuchBeanDefinitionException

    public NoSuchBeanDefinitionException(String name,
                                 String message)

Create a new `NoSuchBeanDefinitionException`.

Parameters:
  `name` - the name of the missing bean
  `message` - detailed message describing the problem

#### NoSuchBeanDefinitionException

    public NoSuchBeanDefinitionException(Class<?> type)

Create a new `NoSuchBeanDefinitionException`.

Parameters:
  `type` - required type of the missing bean

#### NoSuchBeanDefinitionException

    public NoSuchBeanDefinitionException(Class<?> type,
                                 String message)

Create a new `NoSuchBeanDefinitionException`.

Parameters:
  `type` - required type of the missing bean
  `message` - detailed message describing the problem

#### NoSuchBeanDefinitionException

    public NoSuchBeanDefinitionException(Class<?> type,
                                 String dependencyDescription,
                                 String message)

Create a new `NoSuchBeanDefinitionException`.

Parameters:
  `type` - required type of the missing bean
  `dependencyDescription` - a description of the originating dependency
  `message` - detailed message describing the problem

### Method Detail

#### getBeanName

    public String getBeanName()

Return the name of the missing bean, if it was a lookup by name that failed.

#### getBeanType

    public Class<?> getBeanType()

Return the required type of the missing bean, if it was a lookup by type that failed.

#### getNumberOfBeansFound

    public int getNumberOfBeansFound()

Return the number of beans found when only one matching bean was expected. For a regular NoSuchBeanDefinitionException, this will always be 0.

See Also:
  `NoUniqueBeanDefinitionException`