Top Description Fields Constructors Methods
org.springframework.beans.factory.support

public final Class BeanDefinitionBuilder

extends Object
Class Inheritance
Imports
java.util.function.Supplier, org.springframework.beans.factory.config.AutowiredPropertyMarker, .BeanDefinitionCustomizer, .RuntimeBeanReference, org.springframework.core.ResolvableType, org.springframework.lang.Nullable, org.springframework.util.ObjectUtils

Programmatic means of constructing BeanDefinitions using the builder pattern. Intended primarily for use when implementing Spring 2.0 NamespaceHandlers.
Authors
Rod Johnson, Rob Harrop, Juergen Hoeller
Since
2.0

Field Summary

Modifier and TypeField and Description
private final AbstractBeanDefinition
beanDefinition

The BeanDefinition instance we are creating.

private int
constructorArgIndex

Our current position with respect to constructor args.

Constructor Summary

AccessConstructor and Description
private
BeanDefinitionBuilder(AbstractBeanDefinition beanDefinition)

Enforce the use of factory methods.

Method Summary

Modifier and TypeMethod and Description
public BeanDefinitionBuilder
addAutowiredProperty(String
the name of the property to mark as autowired
name
)

Add an autowired marker for the specified property on the specified bean.

public BeanDefinitionBuilder
addConstructorArgReference(String beanName)

Add a reference to a named bean as a constructor arg.

public BeanDefinitionBuilder
addConstructorArgValue(Object value)

Add an indexed constructor arg value.

public BeanDefinitionBuilder
addDependsOn(String beanName)

Append the specified bean name to the list of beans that this definition depends on.

public BeanDefinitionBuilder
addPropertyReference(String
the name of the property to add the reference to
name
,
String
the name of the bean being referenced
beanName
)

Add a reference to the specified bean name under the property specified.

public BeanDefinitionBuilder
addPropertyValue(String name, Object value)

Add the supplied property value under the given property name.

public BeanDefinitionBuilder
applyCustomizers(BeanDefinitionCustomizer... customizers)

Apply the given customizers to the underlying bean definition.

public static BeanDefinitionBuilder
childBeanDefinition(String
the name of the parent bean
parentName
)

Create a new BeanDefinitionBuilder used to construct a ChildBeanDefinition.

public static BeanDefinitionBuilder
genericBeanDefinition()

Create a new BeanDefinitionBuilder used to construct a GenericBeanDefinition.

public static BeanDefinitionBuilder
genericBeanDefinition(String
the class name for the bean that the definition is being created for
beanClassName
)

Create a new BeanDefinitionBuilder used to construct a GenericBeanDefinition.

public static BeanDefinitionBuilder
genericBeanDefinition(Class<?>
the Class of the bean that the definition is being created for
beanClass
)

Create a new BeanDefinitionBuilder used to construct a GenericBeanDefinition.

public static <T> BeanDefinitionBuilder
genericBeanDefinition(Class<T>
the Class of the bean that the definition is being created for
beanClass
,
Supplier<T>
a callback for creating an instance of the bean
instanceSupplier
)

Create a new BeanDefinitionBuilder used to construct a GenericBeanDefinition.

public AbstractBeanDefinition
getBeanDefinition()

Validate and return the created BeanDefinition object.

public AbstractBeanDefinition
getRawBeanDefinition()

Return the current BeanDefinition object in its raw (unvalidated) form.

public static BeanDefinitionBuilder
rootBeanDefinition(String
the class name for the bean that the definition is being created for
beanClassName
)

Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.

public static BeanDefinitionBuilder
rootBeanDefinition(String
the class name for the bean that the definition is being created for
beanClassName
,
String
the name of the method to use to construct the bean instance
factoryMethodName
)

Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.

public static BeanDefinitionBuilder
rootBeanDefinition(Class<?>
the Class of the bean that the definition is being created for
beanClass
)

Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.

public static BeanDefinitionBuilder
rootBeanDefinition(Class<?>
the Class of the bean that the definition is being created for
beanClass
,
String
the name of the method to use to construct the bean instance
factoryMethodName
)

Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.

public static <T> BeanDefinitionBuilder
rootBeanDefinition(ResolvableType
the type of the bean that the definition is being created for
beanType
,
Supplier<T>
a callback for creating an instance of the bean
instanceSupplier
)

Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.

public static <T> BeanDefinitionBuilder
rootBeanDefinition(Class<T>
the Class of the bean that the definition is being created for
beanClass
,
Supplier<T>
a callback for creating an instance of the bean
instanceSupplier
)

Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.

public BeanDefinitionBuilder
setAbstract(boolean flag)

Set whether this definition is abstract.

public BeanDefinitionBuilder
setAutowireMode(int autowireMode)

Set the autowire mode for this definition.

public BeanDefinitionBuilder
setDependencyCheck(int dependencyCheck)

Set the dependency check mode for this definition.

public BeanDefinitionBuilder
setDestroyMethodName(String methodName)

Set the destroy method for this definition.

public BeanDefinitionBuilder
setFactoryMethod(String factoryMethod)

Set the name of a static factory method to use for this definition, to be called on this bean's class.

public BeanDefinitionBuilder
setFactoryMethodOnBean(String
the name of the factory method
factoryMethod
,
String
the name of the bean to call the specified factory method on
factoryBean
)

Set the name of a non-static factory method to use for this definition, including the bean name of the factory instance to call the method on.

public BeanDefinitionBuilder
setInitMethodName(String methodName)

Set the init method for this definition.

public BeanDefinitionBuilder
setLazyInit(boolean lazy)

Set whether beans for this definition should be lazily initialized or not.

public BeanDefinitionBuilder
setParentName(String parentName)

Set the name of the parent definition of this bean definition.

public BeanDefinitionBuilder
setPrimary(boolean primary)

Set whether this bean is a primary autowire candidate.

public BeanDefinitionBuilder
setRole(int role)

Set the role of this definition.

public BeanDefinitionBuilder
setScope(String scope)

Set the scope of this definition.

public BeanDefinitionBuilder
setSynthetic(boolean synthetic)

Set whether this bean is 'synthetic', that is, not defined by the application itself.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

beanDefinitionback to summary
private final AbstractBeanDefinition beanDefinition

The BeanDefinition instance we are creating.

constructorArgIndexback to summary
private int constructorArgIndex

Our current position with respect to constructor args.

Constructor Detail

BeanDefinitionBuilderback to summary
private BeanDefinitionBuilder(AbstractBeanDefinition beanDefinition)

Enforce the use of factory methods.

Method Detail

addAutowiredPropertyback to summary
public BeanDefinitionBuilder addAutowiredProperty(String name)

Add an autowired marker for the specified property on the specified bean.

Parameters
name:String

the name of the property to mark as autowired

Since
5.2
See Also
AutowiredPropertyMarker
addConstructorArgReferenceback to summary
public BeanDefinitionBuilder addConstructorArgReference(String beanName)

Add a reference to a named bean as a constructor arg.

See Also
addConstructorArgValue(Object)
addConstructorArgValueback to summary
public BeanDefinitionBuilder addConstructorArgValue(Object value)

Add an indexed constructor arg value. The current index is tracked internally and all additions are at the present point.

addDependsOnback to summary
public BeanDefinitionBuilder addDependsOn(String beanName)

Append the specified bean name to the list of beans that this definition depends on.

addPropertyReferenceback to summary
public BeanDefinitionBuilder addPropertyReference(String name, String beanName)

Add a reference to the specified bean name under the property specified.

Parameters
name:String

the name of the property to add the reference to

beanName:String

the name of the bean being referenced

addPropertyValueback to summary
public BeanDefinitionBuilder addPropertyValue(String name, Object value)

Add the supplied property value under the given property name.

applyCustomizersback to summary
public BeanDefinitionBuilder applyCustomizers(BeanDefinitionCustomizer... customizers)

Apply the given customizers to the underlying bean definition.

Since
5.0
childBeanDefinitionback to summary
public static BeanDefinitionBuilder childBeanDefinition(String parentName)

Create a new BeanDefinitionBuilder used to construct a ChildBeanDefinition.

Parameters
parentName:String

the name of the parent bean

genericBeanDefinitionback to summary
public static BeanDefinitionBuilder genericBeanDefinition()

Create a new BeanDefinitionBuilder used to construct a GenericBeanDefinition.

genericBeanDefinitionback to summary
public static BeanDefinitionBuilder genericBeanDefinition(String beanClassName)

Create a new BeanDefinitionBuilder used to construct a GenericBeanDefinition.

Parameters
beanClassName:String

the class name for the bean that the definition is being created for

genericBeanDefinitionback to summary
public static BeanDefinitionBuilder genericBeanDefinition(Class<?> beanClass)

Create a new BeanDefinitionBuilder used to construct a GenericBeanDefinition.

Parameters
beanClass:Class<?>

the Class of the bean that the definition is being created for

genericBeanDefinitionback to summary
public static <T> BeanDefinitionBuilder genericBeanDefinition(Class<T> beanClass, Supplier<T> instanceSupplier)

Create a new BeanDefinitionBuilder used to construct a GenericBeanDefinition.

Parameters
beanClass:Class<T>

the Class of the bean that the definition is being created for

instanceSupplier:Supplier<T>

a callback for creating an instance of the bean

Since
5.0
getBeanDefinitionback to summary
public AbstractBeanDefinition getBeanDefinition()

Validate and return the created BeanDefinition object.

getRawBeanDefinitionback to summary
public AbstractBeanDefinition getRawBeanDefinition()

Return the current BeanDefinition object in its raw (unvalidated) form.

See Also
getBeanDefinition()
rootBeanDefinitionback to summary
public static BeanDefinitionBuilder rootBeanDefinition(String beanClassName)

Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.

Parameters
beanClassName:String

the class name for the bean that the definition is being created for

rootBeanDefinitionback to summary
public static BeanDefinitionBuilder rootBeanDefinition(String beanClassName, String factoryMethodName)

Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.

Parameters
beanClassName:String

the class name for the bean that the definition is being created for

factoryMethodName:String

the name of the method to use to construct the bean instance

rootBeanDefinitionback to summary
public static BeanDefinitionBuilder rootBeanDefinition(Class<?> beanClass)

Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.

Parameters
beanClass:Class<?>

the Class of the bean that the definition is being created for

rootBeanDefinitionback to summary
public static BeanDefinitionBuilder rootBeanDefinition(Class<?> beanClass, String factoryMethodName)

Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.

Parameters
beanClass:Class<?>

the Class of the bean that the definition is being created for

factoryMethodName:String

the name of the method to use to construct the bean instance

rootBeanDefinitionback to summary
public static <T> BeanDefinitionBuilder rootBeanDefinition(ResolvableType beanType, Supplier<T> instanceSupplier)

Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.

Parameters
beanType:ResolvableType

the type of the bean that the definition is being created for

instanceSupplier:Supplier<T>

a callback for creating an instance of the bean

Since
5.3.9
rootBeanDefinitionback to summary
public static <T> BeanDefinitionBuilder rootBeanDefinition(Class<T> beanClass, Supplier<T> instanceSupplier)

Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.

Parameters
beanClass:Class<T>

the Class of the bean that the definition is being created for

instanceSupplier:Supplier<T>

a callback for creating an instance of the bean

Since
5.3.9
See Also
rootBeanDefinition(ResolvableType, Supplier)
setAbstractback to summary
public BeanDefinitionBuilder setAbstract(boolean flag)

Set whether this definition is abstract.

setAutowireModeback to summary
public BeanDefinitionBuilder setAutowireMode(int autowireMode)

Set the autowire mode for this definition.

setDependencyCheckback to summary
public BeanDefinitionBuilder setDependencyCheck(int dependencyCheck)

Set the dependency check mode for this definition.

setDestroyMethodNameback to summary
public BeanDefinitionBuilder setDestroyMethodName(String methodName)

Set the destroy method for this definition.

setFactoryMethodback to summary
public BeanDefinitionBuilder setFactoryMethod(String factoryMethod)

Set the name of a static factory method to use for this definition, to be called on this bean's class.

setFactoryMethodOnBeanback to summary
public BeanDefinitionBuilder setFactoryMethodOnBean(String factoryMethod, String factoryBean)

Set the name of a non-static factory method to use for this definition, including the bean name of the factory instance to call the method on.

Parameters
factoryMethod:String

the name of the factory method

factoryBean:String

the name of the bean to call the specified factory method on

Since
4.3.6
setInitMethodNameback to summary
public BeanDefinitionBuilder setInitMethodName(String methodName)

Set the init method for this definition.

setLazyInitback to summary
public BeanDefinitionBuilder setLazyInit(boolean lazy)

Set whether beans for this definition should be lazily initialized or not.

setParentNameback to summary
public BeanDefinitionBuilder setParentName(String parentName)

Set the name of the parent definition of this bean definition.

setPrimaryback to summary
public BeanDefinitionBuilder setPrimary(boolean primary)

Set whether this bean is a primary autowire candidate.

Since
5.1.11
setRoleback to summary
public BeanDefinitionBuilder setRole(int role)

Set the role of this definition.

setScopeback to summary
public BeanDefinitionBuilder setScope(String scope)

Set the scope of this definition.

See Also
org.springframework.beans.factory.config.BeanDefinition#SCOPE_SINGLETON, org.springframework.beans.factory.config.BeanDefinition#SCOPE_PROTOTYPE
setSyntheticback to summary
public BeanDefinitionBuilder setSynthetic(boolean synthetic)

Set whether this bean is 'synthetic', that is, not defined by the application itself.

Since
5.3.9