Package org.springframework.beans.factory

# Class BeanCreationException

java.lang.Object
java.lang.Throwable
java.lang.Exception
java.lang.RuntimeException
org.springframework.core.NestedRuntimeException
org.springframework.beans.BeansException
org.springframework.beans.FatalBeanException
org.springframework.beans.factory.BeanCreationException

All Implemented Interfaces:
  `Serializable`

Direct Known Subclasses:
  `BeanCreationNotAllowedException`, `BeanCurrentlyInCreationException`, `BeanIsAbstractException`, `ScopeNotActiveException`, `UnsatisfiedDependencyException`

public class BeanCreationException extends FatalBeanException
Exception thrown when a BeanFactory encounters an error when attempting to create a bean from a bean definition.

Author:
  Juergen Hoeller
See Also:
  - Serialized Form

## Constructor Summary

Constructors
Constructor
Description
`BeanCreationException(String msg)`
Create a new BeanCreationException.
`BeanCreationException(String beanName, String msg)`
Create a new BeanCreationException.
`BeanCreationException(String resourceDescription, String beanName, String msg)`
Create a new BeanCreationException.
`BeanCreationException(String resourceDescription, String beanName, String msg, Throwable cause)`
Create a new BeanCreationException.
`BeanCreationException(String beanName, String msg, Throwable cause)`
Create a new BeanCreationException.
`BeanCreationException(String msg, Throwable cause)`
Create a new BeanCreationException.

## Method Summary

Modifier and Type
Method
Description
`void`
`addRelatedCause(Throwable ex)`
Add a related cause to this bean creation exception, not being a direct cause of the failure but having occurred earlier in the creation of the same bean instance.
`boolean`
`contains(Class<?> exClass)`
`String`
`getBeanName()`
Return the name of the bean requested, if any.
`Throwable[]`
`getRelatedCauses()`
Return the related causes, if any.
`String`
`getResourceDescription()`
Return the description of the resource that the bean definition came from, if any.
`void`
`printStackTrace(PrintStream ps)`
`void`
`printStackTrace(PrintWriter pw)`
`String`
`toString()`

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

`getMostSpecificCause, getRootCause`

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

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

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

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

## Constructor Details

### BeanCreationException

public BeanCreationException(String msg)
Create a new BeanCreationException.

Parameters:
  `msg` - the detail message

### BeanCreationException

public BeanCreationException(String msg, Throwable cause)
Create a new BeanCreationException.

Parameters:
  `msg` - the detail message
  `cause` - the root cause

### BeanCreationException

public BeanCreationException(String beanName, String msg)
Create a new BeanCreationException.

Parameters:
  `beanName` - the name of the bean requested
  `msg` - the detail message

### BeanCreationException

public BeanCreationException(String beanName, String msg, Throwable cause)
Create a new BeanCreationException.

Parameters:
  `beanName` - the name of the bean requested
  `msg` - the detail message
  `cause` - the root cause

### BeanCreationException

public BeanCreationException(@Nullable String resourceDescription, @Nullable String beanName, @Nullable String msg)
Create a new BeanCreationException.

Parameters:
  `resourceDescription` - description of the resource that the bean definition came from
  `beanName` - the name of the bean requested
  `msg` - the detail message

### BeanCreationException

public BeanCreationException(@Nullable String resourceDescription, String beanName, @Nullable String msg, Throwable cause)
Create a new BeanCreationException.

Parameters:
  `resourceDescription` - description of the resource that the bean definition came from
  `beanName` - the name of the bean requested
  `msg` - the detail message
  `cause` - the root cause

## Method Details

### getResourceDescription

@Nullable public String getResourceDescription()
Return the description of the resource that the bean definition came from, if any.

### getBeanName

@Nullable public String getBeanName()
Return the name of the bean requested, if any.

### addRelatedCause

public void addRelatedCause(Throwable ex)
Add a related cause to this bean creation exception, not being a direct cause of the failure but having occurred earlier in the creation of the same bean instance.

Parameters:
  `ex` - the related cause to add

### getRelatedCauses

@Nullable public Throwable[] getRelatedCauses()
Return the related causes, if any.

Returns:
  the array of related causes, or `null` if none

### toString

public String toString()

Overrides:
  `toString` in class `Throwable`

### printStackTrace

public void printStackTrace(PrintStream ps)

Overrides:
  `printStackTrace` in class `Throwable`

### printStackTrace

public void printStackTrace(PrintWriter pw)

Overrides:
  `printStackTrace` in class `Throwable`

### contains

public boolean contains(@Nullable Class<?> exClass)

Overrides:
  `contains` in class `org.springframework.core.NestedRuntimeException`