Top Description Fields Methods
org.springframework.beans.factory.config

public Interface BeanDefinition

extends AttributeAccessor, BeanMetadataElement
Known Direct Subinterfaces
org.springframework.beans.factory.annotation.AnnotatedBeanDefinition
Known Direct Implementers
org.springframework.beans.factory.support.AbstractBeanDefinition
Imports
org.springframework.beans.BeanMetadataElement, .MutablePropertyValues, org.springframework.core.AttributeAccessor, .ResolvableType, org.springframework.lang.Nullable

A BeanDefinition describes a bean instance, which has property values, constructor argument values, and further information supplied by concrete implementations.

This is just a minimal interface: The main intention is to allow a BeanFactoryPostProcessor to introspect and modify property values and other bean metadata.

Authors
Juergen Hoeller, Rob Harrop
Since
19.03.2004
See Also
ConfigurableListableBeanFactory#getBeanDefinition, org.springframework.beans.factory.support.RootBeanDefinition, org.springframework.beans.factory.support.ChildBeanDefinition

Field Summary

Modifier and TypeField and Description
public static final int
ROLE_APPLICATION

Role hint indicating that a BeanDefinition is a major part of the application.

public static final int
ROLE_INFRASTRUCTURE

Role hint indicating that a BeanDefinition is providing an entirely background role and has no relevance to the end-user.

public static final int
ROLE_SUPPORT

Role hint indicating that a BeanDefinition is a supporting part of some larger configuration, typically an outer org.springframework.beans.factory.parsing.ComponentDefinition.

public static final String
SCOPE_PROTOTYPE

Scope identifier for the standard prototype scope: prototype.

public static final String
SCOPE_SINGLETON

Scope identifier for the standard singleton scope: singleton.

Method Summary

Modifier and TypeMethod and Description
public String
getBeanClassName()

Return the current bean class name of this bean definition.

public ConstructorArgumentValues

Returns:

the ConstructorArgumentValues object (never null)
getConstructorArgumentValues
()

Return the constructor argument values for this bean.

public String[]
getDependsOn()

Return the bean names that this bean depends on.

public String
getDescription()

Return a human-readable description of this bean definition.

public String
getDestroyMethodName()

Return the name of the destroy method.

public String
getFactoryBeanName()

Return the factory bean name, if any.

public String
getFactoryMethodName()

Return a factory method, if any.

public String
getInitMethodName()

Return the name of the initializer method.

public BeanDefinition
getOriginatingBeanDefinition()

Return the originating BeanDefinition, or null if none.

public String
getParentName()

Return the name of the parent definition of this bean definition, if any.

public MutablePropertyValues

Returns:

the MutablePropertyValues object (never null)
getPropertyValues
()

Return the property values to be applied to a new instance of the bean.

public ResolvableType

Returns:

the resolvable type (potentially ResolvableType#NONE)
getResolvableType
()

Return a resolvable type for this bean definition, based on the bean class or other specific metadata.

public String
getResourceDescription()

Return a description of the resource that this bean definition came from (for the purpose of showing context in case of errors).

public int
getRole()

Get the role hint for this BeanDefinition.

public String
getScope()

Return the name of the current target scope for this bean, or null if not known yet.

public default boolean
hasConstructorArgumentValues()

Return if there are constructor argument values defined for this bean.

public default boolean
hasPropertyValues()

Return if there are property values defined for this bean.

public boolean
isAbstract()

Return whether this bean is "abstract", that is, not meant to be instantiated.

public boolean
isAutowireCandidate()

Return whether this bean is a candidate for getting autowired into some other bean.

public boolean
isLazyInit()

Return whether this bean should be lazily initialized, i.e. not eagerly instantiated on startup.

public boolean
isPrimary()

Return whether this bean is a primary autowire candidate.

public boolean
isPrototype()

Return whether this a Prototype, with an independent instance returned for each call.

public boolean
isSingleton()

Return whether this a Singleton, with a single, shared instance returned on all calls.

public void
setAutowireCandidate(boolean autowireCandidate)

Set whether this bean is a candidate for getting autowired into some other bean.

public void
setBeanClassName(String beanClassName)

Specify the bean class name of this bean definition.

public void
setDependsOn(String... dependsOn)

Set the names of the beans that this bean depends on being initialized.

public void
setDescription(String description)

Set a human-readable description of this bean definition.

public void
setDestroyMethodName(String destroyMethodName)

Set the name of the destroy method.

public void
setFactoryBeanName(String factoryBeanName)

Specify the factory bean to use, if any.

public void
setFactoryMethodName(String factoryMethodName)

Specify a factory method, if any.

public void
setInitMethodName(String initMethodName)

Set the name of the initializer method.

public void
setLazyInit(boolean lazyInit)

Set whether this bean should be lazily initialized.

public void
setParentName(String parentName)

Set the name of the parent definition of this bean definition, if any.

public void
setPrimary(boolean primary)

Set whether this bean is a primary autowire candidate.

public void
setRole(int role)

Set the role hint for this BeanDefinition.

public void
setScope(String scope)

Override the target scope of this bean, specifying a new scope name.

Inherited from org.springframework.beans.BeanMetadataElement:
getSource
Inherited from org.springframework.core.AttributeAccessor:
attributeNamescomputeAttributegetAttributehasAttributeremoveAttributesetAttribute

Field Detail

ROLE_APPLICATIONback to summary
public static final int ROLE_APPLICATION

Role hint indicating that a BeanDefinition is a major part of the application. Typically corresponds to a user-defined bean.

ROLE_INFRASTRUCTUREback to summary
public static final int ROLE_INFRASTRUCTURE

Role hint indicating that a BeanDefinition is providing an entirely background role and has no relevance to the end-user. This hint is used when registering beans that are completely part of the internal workings of a org.springframework.beans.factory.parsing.ComponentDefinition.

ROLE_SUPPORTback to summary
public static final int ROLE_SUPPORT

Role hint indicating that a BeanDefinition is a supporting part of some larger configuration, typically an outer org.springframework.beans.factory.parsing.ComponentDefinition. SUPPORT beans are considered important enough to be aware of when looking more closely at a particular org.springframework.beans.factory.parsing.ComponentDefinition, but not when looking at the overall configuration of an application.

SCOPE_PROTOTYPEback to summary
public static final String SCOPE_PROTOTYPE

Scope identifier for the standard prototype scope: prototype.

Note that extended bean factories might support further scopes.

See Also
setScope, ConfigurableBeanFactory#SCOPE_PROTOTYPE
SCOPE_SINGLETONback to summary
public static final String SCOPE_SINGLETON

Scope identifier for the standard singleton scope: singleton.

Note that extended bean factories might support further scopes.

See Also
setScope, ConfigurableBeanFactory#SCOPE_SINGLETON

Method Detail

getBeanClassNameback to summary
public String getBeanClassName()

Return the current bean class name of this bean definition.

Note that this does not have to be the actual class name used at runtime, in case of a child definition overriding/inheriting the class name from its parent. Also, this may just be the class that a factory method is called on, or it may even be empty in case of a factory bean reference that a method is called on. Hence, do not consider this to be the definitive bean type at runtime but rather only use it for parsing purposes at the individual bean definition level.

Annotations
@Nullable
See Also
getParentName(), getFactoryBeanName(), getFactoryMethodName()
getConstructorArgumentValuesback to summary
public ConstructorArgumentValues getConstructorArgumentValues()

Return the constructor argument values for this bean.

The returned instance can be modified during bean factory post-processing.

Returns:ConstructorArgumentValues

the ConstructorArgumentValues object (never null)

getDependsOnback to summary
public String[] getDependsOn()

Return the bean names that this bean depends on.

Annotations
@Nullable
getDescriptionback to summary
public String getDescription()

Return a human-readable description of this bean definition.

Annotations
@Nullable
getDestroyMethodNameback to summary
public String getDestroyMethodName()

Return the name of the destroy method.

Annotations
@Nullable
Since
5.1
getFactoryBeanNameback to summary
public String getFactoryBeanName()

Return the factory bean name, if any.

Annotations
@Nullable
getFactoryMethodNameback to summary
public String getFactoryMethodName()

Return a factory method, if any.

Annotations
@Nullable
getInitMethodNameback to summary
public String getInitMethodName()

Return the name of the initializer method.

Annotations
@Nullable
Since
5.1
getOriginatingBeanDefinitionback to summary
public BeanDefinition getOriginatingBeanDefinition()

Return the originating BeanDefinition, or null if none.

Allows for retrieving the decorated bean definition, if any.

Note that this method returns the immediate originator. Iterate through the originator chain to find the original BeanDefinition as defined by the user.

Annotations
@Nullable
getParentNameback to summary
public String getParentName()

Return the name of the parent definition of this bean definition, if any.

Annotations
@Nullable
getPropertyValuesback to summary
public MutablePropertyValues getPropertyValues()

Return the property values to be applied to a new instance of the bean.

The returned instance can be modified during bean factory post-processing.

Returns:MutablePropertyValues

the MutablePropertyValues object (never null)

getResolvableTypeback to summary
public ResolvableType getResolvableType()

Return a resolvable type for this bean definition, based on the bean class or other specific metadata.

This is typically fully resolved on a runtime-merged bean definition but not necessarily on a configuration-time definition instance.

Returns:ResolvableType

the resolvable type (potentially ResolvableType#NONE)

Since
5.2
See Also
ConfigurableBeanFactory#getMergedBeanDefinition
getResourceDescriptionback to summary
public String getResourceDescription()

Return a description of the resource that this bean definition came from (for the purpose of showing context in case of errors).

Annotations
@Nullable
getRoleback to summary
public int getRole()

Get the role hint for this BeanDefinition. The role hint provides the frameworks as well as tools an indication of the role and importance of a particular BeanDefinition.

See Also
ROLE_APPLICATION, ROLE_SUPPORT, ROLE_INFRASTRUCTURE
getScopeback to summary
public String getScope()

Return the name of the current target scope for this bean, or null if not known yet.

Annotations
@Nullable
hasConstructorArgumentValuesback to summary
public default boolean hasConstructorArgumentValues()

Return if there are constructor argument values defined for this bean.

Since
5.0.2
hasPropertyValuesback to summary
public default boolean hasPropertyValues()

Return if there are property values defined for this bean.

Since
5.0.2
isAbstractback to summary
public boolean isAbstract()

Return whether this bean is "abstract", that is, not meant to be instantiated.

isAutowireCandidateback to summary
public boolean isAutowireCandidate()

Return whether this bean is a candidate for getting autowired into some other bean.

isLazyInitback to summary
public boolean isLazyInit()

Return whether this bean should be lazily initialized, i.e. not eagerly instantiated on startup. Only applicable to a singleton bean.

isPrimaryback to summary
public boolean isPrimary()

Return whether this bean is a primary autowire candidate.

isPrototypeback to summary
public boolean isPrototype()

Return whether this a Prototype, with an independent instance returned for each call.

Since
3.0
See Also
SCOPE_PROTOTYPE
isSingletonback to summary
public boolean isSingleton()

Return whether this a Singleton, with a single, shared instance returned on all calls.

See Also
SCOPE_SINGLETON
setAutowireCandidateback to summary
public void setAutowireCandidate(boolean autowireCandidate)

Set whether this bean is a candidate for getting autowired into some other bean.

Note that this flag is designed to only affect type-based autowiring. It does not affect explicit references by name, which will get resolved even if the specified bean is not marked as an autowire candidate. As a consequence, autowiring by name will nevertheless inject a bean if the name matches.

setBeanClassNameback to summary
public void setBeanClassName(String beanClassName)

Specify the bean class name of this bean definition.

The class name can be modified during bean factory post-processing, typically replacing the original class name with a parsed variant of it.

See Also
setParentName, setFactoryBeanName, setFactoryMethodName
setDependsOnback to summary
public void setDependsOn(String... dependsOn)

Set the names of the beans that this bean depends on being initialized. The bean factory will guarantee that these beans get initialized first.

setDescriptionback to summary
public void setDescription(String description)

Set a human-readable description of this bean definition.

Since
5.1
setDestroyMethodNameback to summary
public void setDestroyMethodName(String destroyMethodName)

Set the name of the destroy method.

Since
5.1
setFactoryBeanNameback to summary
public void setFactoryBeanName(String factoryBeanName)

Specify the factory bean to use, if any. This the name of the bean to call the specified factory method on.

See Also
setFactoryMethodName
setFactoryMethodNameback to summary
public void setFactoryMethodName(String factoryMethodName)

Specify a factory method, if any. This method will be invoked with constructor arguments, or with no arguments if none are specified. The method will be invoked on the specified factory bean, if any, or otherwise as a static method on the local bean class.

See Also
setFactoryBeanName, setBeanClassName
setInitMethodNameback to summary
public void setInitMethodName(String initMethodName)

Set the name of the initializer method.

Since
5.1
setLazyInitback to summary
public void setLazyInit(boolean lazyInit)

Set whether this bean should be lazily initialized.

If false, the bean will get instantiated on startup by bean factories that perform eager initialization of singletons.

setParentNameback to summary
public void setParentName(String parentName)

Set the name of the parent definition of this bean definition, if any.

setPrimaryback to summary
public void setPrimary(boolean primary)

Set whether this bean is a primary autowire candidate.

If this value is true for exactly one bean among multiple matching candidates, it will serve as a tie-breaker.

setRoleback to summary
public void setRole(int role)

Set the role hint for this BeanDefinition. The role hint provides the frameworks as well as tools an indication of the role and importance of a particular BeanDefinition.

Since
5.1
See Also
ROLE_APPLICATION, ROLE_SUPPORT, ROLE_INFRASTRUCTURE
setScopeback to summary
public void setScope(String scope)

Override the target scope of this bean, specifying a new scope name.

See Also
SCOPE_SINGLETON, SCOPE_PROTOTYPE