Package org.springframework.beans.factory.support

# Interface BeanDefinitionRegistry

All Superinterfaces:
  `org.springframework.core.AliasRegistry`

All Known Implementing Classes:
  `DefaultListableBeanFactory`, `SimpleBeanDefinitionRegistry`

public interface BeanDefinitionRegistry extends org.springframework.core.AliasRegistry
Interface for registries that hold bean definitions, for example RootBeanDefinition and ChildBeanDefinition instances. Typically implemented by BeanFactories that internally work with the AbstractBeanDefinition hierarchy.

This is the only interface in Spring's bean factory packages that encapsulates registration of bean definitions. The standard BeanFactory interfaces only cover access to a fully configured factory instance.

Spring's bean definition readers expect to work on an implementation of this interface. Known implementors within the Spring core are DefaultListableBeanFactory and GenericApplicationContext.

Since:
  26.11.2003
Author:
  Juergen Hoeller
See Also:
  - `BeanDefinition`
  - `AbstractBeanDefinition`
  - `RootBeanDefinition`
  - `ChildBeanDefinition`
  - `DefaultListableBeanFactory`
  - `org.springframework.context.support.GenericApplicationContext`
  - `XmlBeanDefinitionReader`

## Method Summary

Modifier and Type
Method
Description
`boolean`
`containsBeanDefinition(String beanName)`
Check if this registry contains a bean definition with the given name.
`BeanDefinition`
`getBeanDefinition(String beanName)`
Return the BeanDefinition for the given bean name.
`int`
`getBeanDefinitionCount()`
Return the number of beans defined in the registry.
`String[]`
`getBeanDefinitionNames()`
Return the names of all beans defined in this registry.
`default boolean`
`isBeanDefinitionOverridable(String beanName)`
Determine whether the bean definition for the given name is overridable, i.e.
`boolean`
`isBeanNameInUse(String beanName)`
Determine whether the given bean name is already in use within this registry, i.e.
`void`
`registerBeanDefinition(String beanName, BeanDefinition beanDefinition)`
Register a new bean definition with this registry.
`void`
`removeBeanDefinition(String beanName)`
Remove the BeanDefinition for the given name.

### Methods inherited from interface org.springframework.core.AliasRegistry

`getAliases, isAlias, registerAlias, removeAlias`

## Method Details

### registerBeanDefinition

void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) throws BeanDefinitionStoreException
Register a new bean definition with this registry. Must support RootBeanDefinition and ChildBeanDefinition.

Parameters:
  `beanName` - the name of the bean instance to register
  `beanDefinition` - definition of the bean instance to register
Throws:
  `BeanDefinitionStoreException` - if the BeanDefinition is invalid
  `BeanDefinitionOverrideException` - if there is already a BeanDefinition for the specified bean name and we are not allowed to override it
See Also:
  - `GenericBeanDefinition`
  - `RootBeanDefinition`
  - `ChildBeanDefinition`

### removeBeanDefinition

void removeBeanDefinition(String beanName) throws NoSuchBeanDefinitionException
Remove the BeanDefinition for the given name.

Parameters:
  `beanName` - the name of the bean instance to register
Throws:
  `NoSuchBeanDefinitionException` - if there is no such bean definition

### getBeanDefinition

BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException
Return the BeanDefinition for the given bean name.

Parameters:
  `beanName` - name of the bean to find a definition for
Returns:
  the BeanDefinition for the given name (never `null`)
Throws:
  `NoSuchBeanDefinitionException` - if there is no such bean definition

### containsBeanDefinition

boolean containsBeanDefinition(String beanName)
Check if this registry contains a bean definition with the given name.

Parameters:
  `beanName` - the name of the bean to look for
Returns:
  if this registry contains a bean definition with the given name

### getBeanDefinitionNames

String[] getBeanDefinitionNames()
Return the names of all beans defined in this registry.

Returns:
  the names of all beans defined in this registry, or an empty array if none defined

### getBeanDefinitionCount

int getBeanDefinitionCount()
Return the number of beans defined in the registry.

Returns:
  the number of beans defined in the registry

### isBeanDefinitionOverridable

default boolean isBeanDefinitionOverridable(String beanName)
Determine whether the bean definition for the given name is overridable, i.e. whether `registerBeanDefinition(java.lang.String, org.springframework.beans.factory.config.BeanDefinition)` would successfully return against an existing definition of the same name.

The default implementation returns `true`.

Parameters:
  `beanName` - the name to check
Returns:
  whether the definition for the given bean name is overridable
Since:
  6.1

### isBeanNameInUse

boolean isBeanNameInUse(String beanName)
Determine whether the given bean name is already in use within this registry, i.e. whether there is a local bean or alias registered under this name.

Parameters:
  `beanName` - the name to check
Returns:
  whether the given bean name is already in use