Class BeanDefinitionBuilder
java.lang.Object
org.springframework.beans.factory.support.BeanDefinitionBuilder
Programmatic means of constructing
BeanDefinitions
using the builder pattern. Intended primarily for use when implementing Spring 2.0
NamespaceHandlers
.- Since:
- 2.0
- Author:
- Rod Johnson, Rob Harrop, Juergen Hoeller
-
Method Summary
Modifier and TypeMethodDescriptionaddAutowiredProperty
(String name) Add an autowired marker for the specified property on the specified bean.addConstructorArgReference
(String beanName) Add a reference to a named bean as a constructor arg.addConstructorArgValue
(Object value) Add an indexed constructor arg value.addDependsOn
(String beanName) Append the specified bean name to the list of beans that this definition depends on.addPropertyReference
(String name, String beanName) Add a reference to the specified bean name under the property specified.addPropertyValue
(String name, Object value) Add the supplied property value under the given property name.applyCustomizers
(BeanDefinitionCustomizer... customizers) Apply the given customizers to the underlying bean definition.static BeanDefinitionBuilder
childBeanDefinition
(String parentName) Create a newBeanDefinitionBuilder
used to construct aChildBeanDefinition
.static BeanDefinitionBuilder
Create a newBeanDefinitionBuilder
used to construct aGenericBeanDefinition
.static BeanDefinitionBuilder
genericBeanDefinition
(Class<?> beanClass) Create a newBeanDefinitionBuilder
used to construct aGenericBeanDefinition
.static <T> BeanDefinitionBuilder
genericBeanDefinition
(Class<T> beanClass, Supplier<T> instanceSupplier) Create a newBeanDefinitionBuilder
used to construct aGenericBeanDefinition
.static BeanDefinitionBuilder
genericBeanDefinition
(String beanClassName) Create a newBeanDefinitionBuilder
used to construct aGenericBeanDefinition
.Validate and return the created BeanDefinition object.Return the current BeanDefinition object in its raw (unvalidated) form.static BeanDefinitionBuilder
rootBeanDefinition
(Class<?> beanClass) Create a newBeanDefinitionBuilder
used to construct aRootBeanDefinition
.static BeanDefinitionBuilder
rootBeanDefinition
(Class<?> beanClass, String factoryMethodName) Create a newBeanDefinitionBuilder
used to construct aRootBeanDefinition
.static <T> BeanDefinitionBuilder
rootBeanDefinition
(Class<T> beanClass, Supplier<T> instanceSupplier) Create a newBeanDefinitionBuilder
used to construct aRootBeanDefinition
.static BeanDefinitionBuilder
rootBeanDefinition
(String beanClassName) Create a newBeanDefinitionBuilder
used to construct aRootBeanDefinition
.static BeanDefinitionBuilder
rootBeanDefinition
(String beanClassName, String factoryMethodName) Create a newBeanDefinitionBuilder
used to construct aRootBeanDefinition
.static <T> BeanDefinitionBuilder
rootBeanDefinition
(ResolvableType beanType, Supplier<T> instanceSupplier) Create a newBeanDefinitionBuilder
used to construct aRootBeanDefinition
.setAbstract
(boolean flag) Set whether or not this definition is abstract.setAutowireMode
(int autowireMode) Set the autowire mode for this definition.setDependencyCheck
(int dependencyCheck) Set the dependency check mode for this definition.setDestroyMethodName
(String methodName) Set the destroy method for this definition.setFactoryMethod
(String factoryMethod) Set the name of a static factory method to use for this definition, to be called on this bean's class.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.setInitMethodName
(String methodName) Set the init method for this definition.setLazyInit
(boolean lazy) Set whether beans for this definition should be lazily initialized or not.setParentName
(String parentName) Set the name of the parent definition of this bean definition.setPrimary
(boolean primary) Set whether this bean is a primary autowire candidate.setRole
(int role) Set the role of this definition.Set the scope of this definition.setSynthetic
(boolean synthetic) Set whether this bean is 'synthetic', that is, not defined by the application itself.
-
Method Details
-
genericBeanDefinition
Create a newBeanDefinitionBuilder
used to construct aGenericBeanDefinition
. -
genericBeanDefinition
Create a newBeanDefinitionBuilder
used to construct aGenericBeanDefinition
.- Parameters:
beanClassName
- the class name for the bean that the definition is being created for
-
genericBeanDefinition
Create a newBeanDefinitionBuilder
used to construct aGenericBeanDefinition
.- Parameters:
beanClass
- theClass
of the bean that the definition is being created for
-
genericBeanDefinition
public static <T> BeanDefinitionBuilder genericBeanDefinition(Class<T> beanClass, Supplier<T> instanceSupplier) Create a newBeanDefinitionBuilder
used to construct aGenericBeanDefinition
.- Parameters:
beanClass
- theClass
of the bean that the definition is being created forinstanceSupplier
- a callback for creating an instance of the bean- Since:
- 5.0
-
rootBeanDefinition
Create a newBeanDefinitionBuilder
used to construct aRootBeanDefinition
.- Parameters:
beanClassName
- the class name for the bean that the definition is being created for
-
rootBeanDefinition
public static BeanDefinitionBuilder rootBeanDefinition(String beanClassName, @Nullable String factoryMethodName) Create a newBeanDefinitionBuilder
used to construct aRootBeanDefinition
.- Parameters:
beanClassName
- the class name for the bean that the definition is being created forfactoryMethodName
- the name of the method to use to construct the bean instance
-
rootBeanDefinition
Create a newBeanDefinitionBuilder
used to construct aRootBeanDefinition
.- Parameters:
beanClass
- theClass
of the bean that the definition is being created for
-
rootBeanDefinition
public static BeanDefinitionBuilder rootBeanDefinition(Class<?> beanClass, @Nullable String factoryMethodName) Create a newBeanDefinitionBuilder
used to construct aRootBeanDefinition
.- Parameters:
beanClass
- theClass
of the bean that the definition is being created forfactoryMethodName
- the name of the method to use to construct the bean instance
-
rootBeanDefinition
public static <T> BeanDefinitionBuilder rootBeanDefinition(ResolvableType beanType, Supplier<T> instanceSupplier) Create a newBeanDefinitionBuilder
used to construct aRootBeanDefinition
.- Parameters:
beanType
- thetype
of the bean that the definition is being created forinstanceSupplier
- a callback for creating an instance of the bean- Since:
- 5.3.9
-
rootBeanDefinition
public static <T> BeanDefinitionBuilder rootBeanDefinition(Class<T> beanClass, Supplier<T> instanceSupplier) Create a newBeanDefinitionBuilder
used to construct aRootBeanDefinition
.- Parameters:
beanClass
- theClass
of the bean that the definition is being created forinstanceSupplier
- a callback for creating an instance of the bean- Since:
- 5.3.9
- See Also:
-
childBeanDefinition
Create a newBeanDefinitionBuilder
used to construct aChildBeanDefinition
.- Parameters:
parentName
- the name of the parent bean
-
getRawBeanDefinition
Return the current BeanDefinition object in its raw (unvalidated) form.- See Also:
-
getBeanDefinition
Validate and return the created BeanDefinition object. -
setParentName
Set the name of the parent definition of this bean definition. -
setFactoryMethod
Set the name of a static factory method to use for this definition, to be called on this bean's class. -
setFactoryMethodOnBean
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
- the name of the factory methodfactoryBean
- the name of the bean to call the specified factory method on- Since:
- 4.3.6
-
addConstructorArgValue
Add an indexed constructor arg value. The current index is tracked internally and all additions are at the present point. -
addConstructorArgReference
Add a reference to a named bean as a constructor arg.- See Also:
-
addPropertyValue
Add the supplied property value under the given property name. -
addPropertyReference
Add a reference to the specified bean name under the property specified.- Parameters:
name
- the name of the property to add the reference tobeanName
- the name of the bean being referenced
-
addAutowiredProperty
Add an autowired marker for the specified property on the specified bean.- Parameters:
name
- the name of the property to mark as autowired- Since:
- 5.2
- See Also:
-
setInitMethodName
Set the init method for this definition. -
setDestroyMethodName
Set the destroy method for this definition. -
setScope
Set the scope of this definition. -
setAbstract
Set whether or not this definition is abstract. -
setLazyInit
Set whether beans for this definition should be lazily initialized or not. -
setAutowireMode
Set the autowire mode for this definition. -
setDependencyCheck
Set the dependency check mode for this definition. -
addDependsOn
Append the specified bean name to the list of beans that this definition depends on. -
setPrimary
Set whether this bean is a primary autowire candidate.- Since:
- 5.1.11
-
setRole
Set the role of this definition. -
setSynthetic
Set whether this bean is 'synthetic', that is, not defined by the application itself.- Since:
- 5.3.9
-
applyCustomizers
Apply the given customizers to the underlying bean definition.- Since:
- 5.0
-