org.springframework.beans.factory.support

Class BeanDefinitionBuilder

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


  • public final class BeanDefinitionBuilder
    extends java.lang.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
    • Method Detail

      • genericBeanDefinition

        public static BeanDefinitionBuilder genericBeanDefinition(java.lang.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(java.lang.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(java.lang.Class<T> beanClass,
                                                                      java.util.function.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(java.lang.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(java.lang.String beanClassName,
                                                               @Nullable
                                                               java.lang.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(java.lang.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(java.lang.Class<?> beanClass,
                                                               @Nullable
                                                               java.lang.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
      • childBeanDefinition

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

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

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

        public BeanDefinitionBuilder setFactoryMethod(java.lang.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(java.lang.String factoryMethod,
                                                            java.lang.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.
        Since:
        4.3.6
      • addConstructorArgValue

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

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

        public BeanDefinitionBuilder addPropertyReference(java.lang.String name,
                                                          java.lang.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
      • setDestroyMethodName

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

        public BeanDefinitionBuilder setAbstract(boolean flag)
        Set whether or not 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 depency check mode for this definition.
      • addDependsOn

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