Class BeanDefinitionBuilder

java.lang.Object
org.springframework.beans.factory.support.BeanDefinitionBuilder

public final class BeanDefinitionBuilder extends Object
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, Yanming Zhou
  • Method Details

    • genericBeanDefinition

      public static BeanDefinitionBuilder genericBeanDefinition()
      Create a new BeanDefinitionBuilder used to construct a GenericBeanDefinition.
    • genericBeanDefinition

      public static BeanDefinitionBuilder genericBeanDefinition(String beanClassName)
      Create a new BeanDefinitionBuilder used to construct a GenericBeanDefinition.
      Parameters:
      beanClassName - the class name for the bean that the definition is being created for
    • genericBeanDefinition

      public static BeanDefinitionBuilder genericBeanDefinition(Class<?> beanClass)
      Create a new BeanDefinitionBuilder used to construct a GenericBeanDefinition.
      Parameters:
      beanClass - the Class of the bean that the definition is being created for
    • genericBeanDefinition

      public static <T> BeanDefinitionBuilder genericBeanDefinition(Class<T> beanClass, Supplier<T> instanceSupplier)
      Create a new BeanDefinitionBuilder used to construct a GenericBeanDefinition.
      Parameters:
      beanClass - the Class of the bean that the definition is being created for
      instanceSupplier - a callback for creating an instance of the bean
      Since:
      5.0
    • rootBeanDefinition

      public static BeanDefinitionBuilder rootBeanDefinition(String beanClassName)
      Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.
      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 new BeanDefinitionBuilder used to construct a RootBeanDefinition.
      Parameters:
      beanClassName - the class name for the bean that the definition is being created for
      factoryMethodName - the name of the method to use to construct the bean instance
    • rootBeanDefinition

      public static BeanDefinitionBuilder rootBeanDefinition(Class<?> beanClass)
      Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.
      Parameters:
      beanClass - the Class of the bean that the definition is being created for
    • rootBeanDefinition

      public static BeanDefinitionBuilder rootBeanDefinition(Class<?> beanClass, @Nullable String factoryMethodName)
      Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.
      Parameters:
      beanClass - the Class of the bean that the definition is being created for
      factoryMethodName - 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 new BeanDefinitionBuilder used to construct a RootBeanDefinition.
      Parameters:
      beanType - the type of the bean that the definition is being created for
      instanceSupplier - 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 new BeanDefinitionBuilder used to construct a RootBeanDefinition.
      Parameters:
      beanClass - the Class of the bean that the definition is being created for
      instanceSupplier - a callback for creating an instance of the bean
      Since:
      5.3.9
      See Also:
    • childBeanDefinition

      public static BeanDefinitionBuilder childBeanDefinition(String parentName)
      Create a new BeanDefinitionBuilder used to construct a ChildBeanDefinition.
      Parameters:
      parentName - the name of the parent bean
    • getRawBeanDefinition

      public AbstractBeanDefinition getRawBeanDefinition()
      Return the current BeanDefinition object in its raw (unvalidated) form.
      See Also:
    • getBeanDefinition

      public AbstractBeanDefinition getBeanDefinition()
      Validate and return the created BeanDefinition object.
    • setParentName

      public BeanDefinitionBuilder setParentName(String parentName)
      Set the name of the parent definition of this bean definition.
    • setFactoryMethod

      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.
    • setFactoryMethodOnBean

      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 - the name of the factory method
      factoryBean - the name of the bean to call the specified factory method on
      Since:
      4.3.6
    • addConstructorArgValue

      public BeanDefinitionBuilder addConstructorArgValue(@Nullable Object value)
      Add an indexed constructor arg value. The current index is tracked internally and all additions are at the present point.
    • addConstructorArgReference

      public BeanDefinitionBuilder addConstructorArgReference(String beanName)
      Add a reference to a named bean as a constructor arg.
      See Also:
    • addPropertyValue

      public BeanDefinitionBuilder addPropertyValue(String name, @Nullable Object value)
      Add the supplied property value under the given property name.
    • addPropertyReference

      public BeanDefinitionBuilder addPropertyReference(String name, String beanName)
      Add a reference to the specified bean name under the property specified.
      Parameters:
      name - the name of the property to add the reference to
      beanName - the name of the bean being referenced
    • addAutowiredProperty

      public BeanDefinitionBuilder addAutowiredProperty(String name)
      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

      public BeanDefinitionBuilder setInitMethodName(@Nullable String methodName)
      Set the init method for this definition.
    • setDestroyMethodName

      public BeanDefinitionBuilder setDestroyMethodName(@Nullable String methodName)
      Set the destroy method for this definition.
    • setScope

      public BeanDefinitionBuilder setScope(@Nullable String scope)
      Set the scope of this definition.
      See Also:
    • setAbstract

      public BeanDefinitionBuilder setAbstract(boolean flag)
      Set whether this definition is abstract.
    • setLazyInit

      public BeanDefinitionBuilder setLazyInit(boolean lazy)
      Set whether beans for this definition should be lazily initialized or not.
    • setAutowireMode

      public BeanDefinitionBuilder setAutowireMode(int autowireMode)
      Set the autowire mode for this definition.
    • setDependencyCheck

      public BeanDefinitionBuilder setDependencyCheck(int dependencyCheck)
      Set the dependency check mode for this definition.
    • addDependsOn

      public BeanDefinitionBuilder addDependsOn(String beanName)
      Append the specified bean name to the list of beans that this definition depends on.
    • setPrimary

      public BeanDefinitionBuilder setPrimary(boolean primary)
      Set whether this bean is a primary autowire candidate.
      Since:
      5.1.11
    • setFallback

      public BeanDefinitionBuilder setFallback(boolean fallback)
      Set whether this bean is a fallback autowire candidate.
      Since:
      6.2
    • setRole

      public BeanDefinitionBuilder setRole(int role)
      Set the role of this definition.
    • setSynthetic

      public BeanDefinitionBuilder setSynthetic(boolean synthetic)
      Set whether this bean is 'synthetic', that is, not defined by the application itself.
      Since:
      5.3.9
    • applyCustomizers

      public BeanDefinitionBuilder applyCustomizers(BeanDefinitionCustomizer... customizers)
      Apply the given customizers to the underlying bean definition.
      Since:
      5.0