CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-springframework--spring-beans

Spring Beans - IoC Container and Dependency Injection providing comprehensive bean management infrastructure and dependency injection capabilities.

Pending
Overview
Eval results
Files

bean-definition.mddocs/

Bean Definition and Configuration

Bean definition infrastructure supporting multiple configuration sources (XML, annotations, programmatic) with comprehensive metadata management and validation. This system defines how beans should be created, configured, and managed within the Spring IoC container.

Capabilities

Bean Definition Interface

Core metadata interface that describes a bean instance, including property values, constructor arguments, and other configuration details.

/**
 * A BeanDefinition describes a bean instance, which has property values, constructor argument values, and further information supplied by concrete implementations.
 */
interface BeanDefinition extends AttributeAccessor, BeanMetadataElement {
    /** Scope identifier for the standard singleton scope. */
    String SCOPE_SINGLETON = ConfigurableBeanFactory.SCOPE_SINGLETON;
    /** Scope identifier for the standard prototype scope. */
    String SCOPE_PROTOTYPE = ConfigurableBeanFactory.SCOPE_PROTOTYPE;
    
    /** Role hint indicating that a BeanDefinition is a major part of the application. */
    int ROLE_APPLICATION = 0;
    /** Role hint indicating that a BeanDefinition is a supporting part of some larger configuration. */
    int ROLE_SUPPORT = 1;
    /** Role hint indicating that a BeanDefinition is providing an entirely background role. */
    int ROLE_INFRASTRUCTURE = 2;
    
    /**
     * Set the name of the parent definition of this bean definition, if any.
     * @param parentName the parent name
     */
    void setParentName(String parentName);
    
    /**
     * Return the name of the parent definition of this bean definition, if any.
     * @return the parent name, or null if none is set
     */
    String getParentName();
    
    /**
     * Specify the bean class name of this bean definition.
     * @param beanClassName the bean class name
     */
    void setBeanClassName(String beanClassName);
    
    /**
     * Return the current bean class name of this bean definition.
     * @return the bean class name, or null if none defined
     */
    String getBeanClassName();
    
    /**
     * Override the target scope of this bean, specifying a new scope name.
     * @param scope the new scope name
     */
    void setScope(String scope);
    
    /**
     * Return the name of the current target scope for this bean, or null if not known yet.
     * @return the scope name, or null if none specified
     */
    String getScope();
    
    /**
     * Set whether this bean should be lazily initialized.
     * @param lazyInit whether to apply lazy-init
     */
    void setLazyInit(boolean lazyInit);
    
    /**
     * Return whether this bean should be lazily initialized.
     * @return whether to apply lazy-init
     */
    boolean isLazyInit();
    
    /**
     * Set the names of the beans that this bean depends on being initialized.
     * @param dependsOn the bean names that this bean depends on
     */
    void setDependsOn(String... dependsOn);
    
    /**
     * Return the bean names that this bean depends on.
     * @return the bean names that this bean depends on, or null if none
     */
    String[] getDependsOn();
    
    /**
     * Set whether this bean is a candidate for getting autowired into some other bean.
     * @param autowireCandidate whether this bean is a candidate for autowiring
     */
    void setAutowireCandidate(boolean autowireCandidate);
    
    /**
     * Return whether this bean is a candidate for getting autowired into some other bean.
     * @return whether this bean is a candidate for autowiring
     */
    boolean isAutowireCandidate();
    
    /**
     * Set whether this bean is a primary autowire candidate.
     * @param primary whether this bean is a primary autowire candidate
     */
    void setPrimary(boolean primary);
    
    /**
     * Return whether this bean is a primary autowire candidate.
     * @return whether this bean is a primary autowire candidate
     */
    boolean isPrimary();
    
    /**
     * Specify the factory bean to use, if any.
     * @param factoryBeanName the factory bean name, or null if none
     */
    void setFactoryBeanName(String factoryBeanName);
    
    /**
     * Return the factory bean name, if any.
     * @return the factory bean name, or null if none set
     */
    String getFactoryBeanName();
    
    /**
     * Specify a factory method, if any.
     * @param factoryMethodName the factory method name, or null if none
     */
    void setFactoryMethodName(String factoryMethodName);
    
    /**
     * Return a factory method, if any.
     * @return the factory method name, or null if none specified
     */
    String getFactoryMethodName();
    
    /**
     * Return the constructor argument values for this bean.
     * @return the constructor argument values (never null)
     */
    ConstructorArgumentValues getConstructorArgumentValues();
    
    /**
     * Return if there are constructor argument values defined for this bean.
     * @return if there are constructor argument values defined for this bean
     */
    default boolean hasConstructorArgumentValues() {
        return !getConstructorArgumentValues().isEmpty();
    }
    
    /**
     * Return the property values to be applied to a new instance of the bean.
     * @return the property values for this bean (never null)
     */
    MutablePropertyValues getPropertyValues();
    
    /**
     * Return if there are property values defined for this bean.
     * @return if there are property values defined for this bean
     */
    default boolean hasPropertyValues() {
        return !getPropertyValues().isEmpty();
    }
    
    /**
     * Set the name of the initializer method.
     * @param initMethodName the initializer method name
     */
    void setInitMethodName(String initMethodName);
    
    /**
     * Return the name of the initializer method.
     * @return the initializer method name, or null if none set
     */
    String getInitMethodName();
    
    /**
     * Set the name of the destroy method.
     * @param destroyMethodName the destroy method name
     */
    void setDestroyMethodName(String destroyMethodName);
    
    /**
     * Return the name of the destroy method.
     * @return the destroy method name, or null if none set
     */
    String getDestroyMethodName();
    
    /**
     * Set the role hint for this BeanDefinition.
     * @param role the role hint
     */
    void setRole(int role);
    
    /**
     * Get the role hint for this BeanDefinition.
     * @return the role hint
     */
    int getRole();
    
    /**
     * Set a human-readable description of this bean definition.
     * @param description the description
     */
    void setDescription(String description);
    
    /**
     * Return a human-readable description of this bean definition.
     * @return the description, or null if none set
     */
    String getDescription();
    
    /**
     * Return a resolvable type for this bean definition.
     * @return a resolvable type (never null)
     */
    ResolvableType getResolvableType();
    
    /**
     * Return whether this a Singleton, with a single, shared instance returned on all calls.
     * @return whether this is a singleton
     */
    boolean isSingleton();
    
    /**
     * Return whether this a Prototype, with an independent instance returned for each call.
     * @return whether this is a prototype
     */
    boolean isPrototype();
    
    /**
     * Return whether this bean is "abstract", that is, not meant to be instantiated.
     * @return whether this bean is abstract
     */
    boolean isAbstract();
}

Bean Definition Registry

Central interface for registering bean definitions with the Spring container.

/**
 * Interface for registries that hold bean definitions, for example RootBeanDefinition and ChildBeanDefinition instances.
 */
interface BeanDefinitionRegistry extends AliasRegistry {
    /**
     * Register a new bean definition with this registry.
     * @param beanName the name of the bean instance to register
     * @param beanDefinition definition of the bean instance to register
     * @throws BeanDefinitionStoreException if the BeanDefinition is invalid
     * @throws BeanDefinitionOverrideException if there is already a BeanDefinition for the specified bean name and we are not allowed to override it
     */
    void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) throws BeanDefinitionStoreException;
    
    /**
     * Remove the BeanDefinition for the given name.
     * @param beanName the name of the bean instance to register
     * @throws NoSuchBeanDefinitionException if there is no such bean definition
     */
    void removeBeanDefinition(String beanName) throws NoSuchBeanDefinitionException;
    
    /**
     * Return the BeanDefinition for the given bean name.
     * @param beanName name of the bean to find the definition for
     * @return the BeanDefinition for the given name (never null)
     * @throws NoSuchBeanDefinitionException if there is no such bean definition
     */
    BeanDefinition getBeanDefinition(String beanName) throws NoSuchBeanDefinitionException;
    
    /**
     * Check if this registry contains a bean definition with the given name.
     * @param beanName the name of the bean to look for
     * @return if this registry contains a bean definition with the given name
     */
    boolean containsBeanDefinition(String beanName);
    
    /**
     * Return the names of all beans defined in this registry.
     * @return the names of all beans defined in this registry, or an empty array if none defined
     */
    String[] getBeanDefinitionNames();
    
    /**
     * Return the number of beans defined in the registry.
     * @return the number of beans defined in the registry
     */
    int getBeanDefinitionCount();
    
    /**
     * Determine whether the given bean name is already in use within this registry.
     * @param beanName the name to check
     * @return whether the given bean name is already in use
     */
    boolean isBeanNameInUse(String beanName);
}

Root Bean Definition

Most commonly used concrete BeanDefinition class which supports property values, constructor arguments, and more.

/**
 * A root bean definition represents the merged bean definition at runtime of a specific bean in a Spring BeanFactory.
 */
class RootBeanDefinition extends AbstractBeanDefinition {
    /**
     * Create a new RootBeanDefinition for a singleton.
     */
    public RootBeanDefinition();
    
    /**
     * Create a new RootBeanDefinition for a singleton.
     * @param beanClass the class of the bean to instantiate
     */
    public RootBeanDefinition(Class<?> beanClass);
    
    /**
     * Create a new RootBeanDefinition for a scoped bean.
     * @param beanClass the class of the bean to instantiate
     * @param scope the name of the corresponding scope
     */
    public RootBeanDefinition(Class<?> beanClass, String scope);
    
    /**
     * Create a new RootBeanDefinition for a singleton, using an instance supplier.
     * @param beanClass the class of the bean to instantiate (may be null)
     * @param instanceSupplier the supplier to use for creating bean instances
     */
    public <T> RootBeanDefinition(Class<T> beanClass, Supplier<T> instanceSupplier);
    
    /**
     * Create a new RootBeanDefinition for a scoped bean, using an instance supplier.
     * @param beanClass the class of the bean to instantiate (may be null)
     * @param scope the name of the corresponding scope
     * @param instanceSupplier the supplier to use for creating bean instances
     */
    public <T> RootBeanDefinition(Class<T> beanClass, String scope, Supplier<T> instanceSupplier);
    
    /**
     * Create a new RootBeanDefinition as deep copy of the given bean definition.
     * @param original the original bean definition to copy from
     */
    public RootBeanDefinition(RootBeanDefinition original);
    
    /**
     * Create a new RootBeanDefinition as deep copy of the given bean definition.
     * @param original the original bean definition to copy from
     */
    public RootBeanDefinition(BeanDefinition original);
    
    /**
     * Set a resolved Java Class for this bean definition.
     * @param beanClass the resolved bean class (never null)
     */
    public void setBeanClass(Class<?> beanClass);
    
    /**
     * Return the resolved type of this bean definition.
     * @return the resolved type (never null)
     * @throws IllegalStateException if the bean class is not resolvable
     */
    public Class<?> getBeanClass() throws IllegalStateException;
    
    /**
     * Return whether this definition specifies a bean class.
     * @return true if a bean class is specified
     */
    public boolean hasBeanClass();
    
    /**
     * Determine the class of the wrapped bean, resolving it from a specified class name if necessary.
     * @param classLoader the ClassLoader to use for resolving a (potential) class name
     * @return the resolved bean class
     * @throws ClassNotFoundException if the class name could be resolved
     */
    public Class<?> resolveBeanClass(ClassLoader classLoader) throws ClassNotFoundException;
    
    /**
     * Set a callback for creating an instance of the bean, as an alternative to a declaratively specified factory method.
     * @param instanceSupplier the supplier to use for creating bean instances (may be null)
     */
    public void setInstanceSupplier(Supplier<?> instanceSupplier);
    
    /**
     * Return a callback for creating an instance of the bean, if any.
     * @return the instance supplier, or null if none set
     */
    public Supplier<?> getInstanceSupplier();
    
    /**
     * Specify a factory method name that refers to a non-overloaded method.
     * @param factoryMethodName the factory method name, or null if none
     */
    public void setUniqueFactoryMethodName(String factoryMethodName);
    
    /**
     * Return the resolved factory method as a Java Method object, if available.
     * @return the factory method, or null if not found or not resolved yet
     */
    public Method getResolvedFactoryMethod();
    
    /**
     * Set the resolved constructor to use for this bean definition.
     * @param constructor the constructor to use (may be null)
     */
    public void setResolvedConstructorOrFactoryMethod(Executable constructor);
    
    /**
     * Return the resolved constructor or factory method.
     * @return the constructor or factory method, or null if not resolved yet
     */
    public Executable getResolvedConstructorOrFactoryMethod();
    
    /**
     * Mark the specified constructor as resolved.
     * @param constructorIndex the constructor index
     */
    public void markConstructorArgumentsResolved();
    
    /**
     * Return whether the constructor arguments for this bean have been resolved.
     * @return whether the constructor arguments have been resolved
     */
    public boolean constructorArgumentsResolved();
    
    /**
     * Set pre-resolved constructor arguments.
     * @param constructorArgumentsResolved the constructor arguments (may be null)
     */
    public void setResolvedConstructorArguments(Object[] constructorArgumentsResolved);
    
    /**
     * Return the resolved constructor arguments.
     * @return the resolved constructor arguments, or null if not resolved yet
     */
    public Object[] getResolvedConstructorArguments();
    
    /**
     * Set "prepared" constructor arguments.
     * @param preparedConstructorArguments the prepared constructor arguments (may be null)
     */
    public void setPreparedConstructorArguments(Object[] preparedConstructorArguments);
    
    /**
     * Return the "prepared" constructor arguments.
     * @return the prepared constructor arguments, or null if none
     */
    public Object[] getPreparedConstructorArguments();
}

Generic Bean Definition

Generic bean definition class for any kind of configuration purpose.

/**
 * GenericBeanDefinition is a one-stop shop for standard bean definition purposes.
 */
class GenericBeanDefinition extends AbstractBeanDefinition {
    /**
     * Create a new GenericBeanDefinition for the given bean class.
     */
    public GenericBeanDefinition();
    
    /**
     * Create a new GenericBeanDefinition for the given bean class.
     * @param beanClass the class of the bean to instantiate
     */
    public GenericBeanDefinition(Class<?> beanClass);
    
    /**
     * Create a new GenericBeanDefinition as deep copy of the given bean definition.
     * @param original the original bean definition to copy from
     */
    public GenericBeanDefinition(BeanDefinition original);
    
    /**
     * Set the name of the parent definition of this bean definition, if any.
     * @param parentName the parent name
     */
    public void setParentName(String parentName);
    
    /**
     * Return the name of the parent definition of this bean definition, if any.
     * @return the parent name, or null if none is set
     */
    public String getParentName();
}

Constructor Argument Values

Holder for constructor argument values for a bean.

/**
 * Holder for constructor argument values, typically as part of a bean definition.
 */
class ConstructorArgumentValues {
    /**
     * Create a new empty ConstructorArgumentValues object.
     */
    public ConstructorArgumentValues();
    
    /**
     * Deep copy constructor.
     * @param original the ConstructorArgumentValues to copy
     */
    public ConstructorArgumentValues(ConstructorArgumentValues original);
    
    /**
     * Copy all given argument values into this object.
     * @param other the ConstructorArgumentValues to copy from
     */
    public void addArgumentValues(ConstructorArgumentValues other);
    
    /**
     * Add an argument value for the given index in the constructor argument list.
     * @param index the index in the constructor argument list
     * @param value the argument value
     */
    public void addIndexedArgumentValue(int index, Object value);
    
    /**
     * Add an argument value for the given index in the constructor argument list.
     * @param index the index in the constructor argument list
     * @param value the argument value
     * @param type the type of the constructor argument
     */
    public void addIndexedArgumentValue(int index, Object value, String type);
    
    /**
     * Add an argument value for the given index in the constructor argument list.
     * @param index the index in the constructor argument list
     * @param newValue the argument value in the form of a ValueHolder
     */
    public void addIndexedArgumentValue(int index, ValueHolder newValue);
    
    /**
     * Check whether an argument value has been registered for the given index.
     * @param index the index in the constructor argument list
     * @return whether an argument value has been registered
     */
    public boolean hasIndexedArgumentValue(int index);
    
    /**
     * Get argument value for the given index in the constructor argument list.
     * @param index the index in the constructor argument list
     * @param requiredType the type to match (can be null)
     * @return the ValueHolder for the argument, or null if none set
     */
    public ValueHolder getIndexedArgumentValue(int index, Class<?> requiredType);
    
    /**
     * Return a Map of the indexed argument values held in this instance.
     * @return an unmodifiable Map with Integer index as key and ValueHolder as value
     */
    public Map<Integer, ValueHolder> getIndexedArgumentValues();
    
    /**
     * Add a generic argument value to be matched by type.
     * @param value the argument value
     */
    public void addGenericArgumentValue(Object value);
    
    /**
     * Add a generic argument value to be matched by type.
     * @param value the argument value
     * @param type the type of the constructor argument
     */
    public void addGenericArgumentValue(Object value, String type);
    
    /**
     * Add a generic argument value to be matched by type or name (if available).
     * @param newValue the argument value in the form of a ValueHolder
     */
    public void addGenericArgumentValue(ValueHolder newValue);
    
    /**
     * Look for a generic argument value that matches the given type.
     * @param requiredType the type to match
     * @return the ValueHolder for the argument, or null if none set
     */
    public ValueHolder getGenericArgumentValue(Class<?> requiredType);
    
    /**
     * Look for a generic argument value that matches the given type.
     * @param requiredType the type to match (can be null)
     * @param requiredName the name to match (can be null)
     * @return the ValueHolder for the argument, or null if none set
     */
    public ValueHolder getGenericArgumentValue(Class<?> requiredType, String requiredName);
    
    /**
     * Look for a generic argument value that matches the given type.
     * @param requiredType the type to match (can be null)
     * @param requiredName the name to match (can be null)
     * @param usedValueHolders a Set of ValueHolder objects that have already been used in the current resolution process
     * @return the ValueHolder for the argument, or null if none found
     */
    public ValueHolder getGenericArgumentValue(Class<?> requiredType, String requiredName, Set<ValueHolder> usedValueHolders);
    
    /**
     * Return the list of generic argument values held in this instance.
     * @return an unmodifiable List of ValueHolders
     */
    public List<ValueHolder> getGenericArgumentValues();
    
    /**
     * Look for the next generic argument value that matches the given type, ignoring argument values that have already been used.
     * @param requiredType the type to match (can be null)
     * @param usedValueHolders a Set of ValueHolder objects that have already been used
     * @return the ValueHolder for the argument, or null if none found
     */
    public ValueHolder getArgumentValue(int index, Class<?> requiredType, String requiredName, Set<ValueHolder> usedValueHolders);
    
    /**
     * Return the number of argument values held in this instance.
     * @return the number of argument values
     */
    public int getArgumentCount();
    
    /**
     * Return if this holder does not contain any argument values, neither indexed ones nor generic ones.
     * @return whether this holder does not contain any argument values
     */
    public boolean isEmpty();
    
    /**
     * Clear this holder, removing all argument values.
     */
    public void clear();
    
    /**
     * Holder for a constructor argument value, with an optional type attribute indicating the target type of the actual constructor argument.
     */
    public static class ValueHolder implements BeanMetadataElement {
        /**
         * Create a new ValueHolder for the given value.
         * @param value the argument value
         */
        public ValueHolder(Object value);
        
        /**
         * Create a new ValueHolder for the given value and type.
         * @param value the argument value
         * @param type the type of the constructor argument
         */
        public ValueHolder(Object value, String type);
        
        /**
         * Create a new ValueHolder for the given value, type and name.
         * @param value the argument value
         * @param type the type of the constructor argument
         * @param name the name of the constructor argument
         */
        public ValueHolder(Object value, String type, String name);
        
        /**
         * Set the value for the constructor argument.
         * @param value the argument value
         */
        public void setValue(Object value);
        
        /**
         * Return the value for the constructor argument.
         * @return the argument value
         */
        public Object getValue();
        
        /**
         * Set the type of the constructor argument.
         * @param type the type of the constructor argument
         */
        public void setType(String type);
        
        /**
         * Return the type of the constructor argument.
         * @return the type of the constructor argument
         */
        public String getType();
        
        /**
         * Set the name of the constructor argument.
         * @param name the name of the constructor argument
         */
        public void setName(String name);
        
        /**
         * Return the name of the constructor argument.
         * @return the name of the constructor argument
         */
        public String getName();
        
        /**
         * Return whether this holder contains a converted value already.
         * @return whether this holder contains a converted value already
         */
        public synchronized boolean isConverted();
        
        /**
         * Set the converted value of the constructor argument, after processed type conversion.
         * @param value the converted value
         */
        public synchronized void setConvertedValue(Object value);
        
        /**
         * Return the converted value of the constructor argument, after processed type conversion.
         * @return the converted value
         */
        public synchronized Object getConvertedValue();
    }
}

Usage Examples:

import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.beans.factory.support.GenericBeanDefinition;
import org.springframework.beans.factory.config.ConstructorArgumentValues;
import org.springframework.beans.MutablePropertyValues;

// Create bean factory and registry
DefaultListableBeanFactory registry = new DefaultListableBeanFactory();

// Create a simple bean definition
RootBeanDefinition beanDef = new RootBeanDefinition(MyService.class);
beanDef.setScope("singleton");
beanDef.setLazyInit(false);

// Set property values
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue("name", "My Service");
pvs.addPropertyValue("timeout", 30);
beanDef.setPropertyValues(pvs);

// Set constructor arguments
ConstructorArgumentValues args = new ConstructorArgumentValues();
args.addIndexedArgumentValue(0, "config.properties");
args.addGenericArgumentValue(true); // enable logging
beanDef.setConstructorArgumentValues(args);

// Register the bean definition
registry.registerBeanDefinition("myService", beanDef);

// Create generic bean definition with parent
GenericBeanDefinition childDef = new GenericBeanDefinition();
childDef.setParentName("myService");
childDef.setBeanClassName("com.example.ExtendedService");
childDef.setScope("prototype");

// Override some property values
MutablePropertyValues childPvs = new MutablePropertyValues();
childPvs.addPropertyValue("name", "Extended Service");
childDef.setPropertyValues(childPvs);

registry.registerBeanDefinition("extendedService", childDef);

// Query bean definitions
String[] beanNames = registry.getBeanDefinitionNames();
int count = registry.getBeanDefinitionCount();
boolean exists = registry.containsBeanDefinition("myService");

// Retrieve and modify bean definition
BeanDefinition retrievedDef = registry.getBeanDefinition("myService");
retrievedDef.setDescription("Service for handling business logic");

Bean Definition Holder

Simple holder for a bean definition with a name and aliases.

/**
 * Holder for a BeanDefinition with name and aliases.
 */
class BeanDefinitionHolder implements BeanMetadataElement {
    /**
     * Create a new BeanDefinitionHolder.
     * @param beanDefinition the BeanDefinition to wrap
     * @param beanName the name of the bean, as specified for the bean definition
     */
    public BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName);
    
    /**
     * Create a new BeanDefinitionHolder.
     * @param beanDefinition the BeanDefinition to wrap
     * @param beanName the name of the bean, as specified for the bean definition
     * @param aliases alias names for the bean, or null if none
     */
    public BeanDefinitionHolder(BeanDefinition beanDefinition, String beanName, String[] aliases);
    
    /**
     * Copy constructor: Create a new BeanDefinitionHolder with the same contents as the given BeanDefinitionHolder instance.
     * @param beanDefinitionHolder the BeanDefinitionHolder to copy
     */
    public BeanDefinitionHolder(BeanDefinitionHolder beanDefinitionHolder);
    
    /**
     * Return the wrapped BeanDefinition.
     * @return the wrapped BeanDefinition
     */
    public BeanDefinition getBeanDefinition();
    
    /**
     * Return the primary name of the bean, as specified for the bean definition.
     * @return the primary name of the bean
     */
    public String getBeanName();
    
    /**
     * Return the alias names for the bean, as specified directly for the bean definition.
     * @return the alias names, or null if none specified
     */
    public String[] getAliases();
    
    /**
     * Expose the bean definition's source object.
     * @return the source object (may be null)
     */
    public Object getSource();
    
    /**
     * Determine whether the given candidate name matches the bean name or the aliases stored in this bean definition.
     * @param candidateName the candidate name to check
     * @return whether the candidate name matches
     */
    public boolean matchesName(String candidateName);
    
    /**
     * Return a friendly, short description for the bean, stating name and aliases.
     * @return the short description
     */
    public String getShortDescription();
    
    /**
     * Return a long description for the bean, including name and aliases as well as a description of the contained BeanDefinition.
     * @return the long description
     */
    public String getLongDescription();
}

Bean Definition Builder

Utility class that provides a fluent API for programmatically building bean definitions.

/**
 * Utility class for programmatically building bean definitions.
 */
class BeanDefinitionBuilder {
    /**
     * Create a new BeanDefinitionBuilder used to construct a GenericBeanDefinition.
     * @param beanClass the class of the bean that the definition is being created for
     * @return the BeanDefinitionBuilder
     */
    public static BeanDefinitionBuilder genericBeanDefinition(Class<?> beanClass);
    
    /**
     * Create a new BeanDefinitionBuilder used to construct a GenericBeanDefinition.
     * @param beanClassName the className for the bean that the definition is being created for
     * @return the BeanDefinitionBuilder
     */
    public static BeanDefinitionBuilder genericBeanDefinition(String beanClassName);
    
    /**
     * Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.
     * @param beanClass the class of the bean that the definition is being created for
     * @return the BeanDefinitionBuilder
     */
    public static BeanDefinitionBuilder rootBeanDefinition(Class<?> beanClass);
    
    /**
     * Create a new BeanDefinitionBuilder used to construct a RootBeanDefinition.
     * @param beanClassName the className for the bean that the definition is being created for
     * @return the BeanDefinitionBuilder
     */
    public static BeanDefinitionBuilder rootBeanDefinition(String beanClassName);
    
    /**
     * Create a new BeanDefinitionBuilder used to construct a ChildBeanDefinition.
     * @param parentName the name of the parent bean
     * @return the BeanDefinitionBuilder
     */
    public static BeanDefinitionBuilder childBeanDefinition(String parentName);
    
    /**
     * Set the name of the parent definition of this bean definition.
     * @param parentName the parent name
     * @return the current BeanDefinitionBuilder instance (for method chaining)
     */
    public BeanDefinitionBuilder setParentName(String parentName);
    
    /**
     * Set the factory method to use for creating this bean.
     * @param factoryMethod the factory method name
     * @return the current BeanDefinitionBuilder instance (for method chaining)
     */
    public BeanDefinitionBuilder setFactoryMethod(String factoryMethod);
    
    /**
     * Set the factory bean to use for creating this bean.
     * @param factoryBean the factory bean name
     * @return the current BeanDefinitionBuilder instance (for method chaining)
     */
    public BeanDefinitionBuilder setFactoryBean(String factoryBean);
    
    /**
     * Add a constructor argument value.
     * @param value the constructor argument value
     * @return the current BeanDefinitionBuilder instance (for method chaining)
     */
    public BeanDefinitionBuilder addConstructorArgValue(Object value);
    
    /**
     * Add an indexed constructor argument value.
     * @param index the index of the constructor argument
     * @param value the constructor argument value
     * @return the current BeanDefinitionBuilder instance (for method chaining)
     */
    public BeanDefinitionBuilder addConstructorArgValue(int index, Object value);
    
    /**
     * Add a property value.
     * @param name the property name
     * @param value the property value
     * @return the current BeanDefinitionBuilder instance (for method chaining)
     */
    public BeanDefinitionBuilder addPropertyValue(String name, Object value);
    
    /**
     * Add a property reference.
     * @param name the property name
     * @param beanName the bean name to reference
     * @return the current BeanDefinitionBuilder instance (for method chaining)
     */
    public BeanDefinitionBuilder addPropertyReference(String name, String beanName);
    
    /**
     * Set the init method for this definition.
     * @param methodName the name of the init method
     * @return the current BeanDefinitionBuilder instance (for method chaining)
     */
    public BeanDefinitionBuilder setInitMethodName(String methodName);
    
    /**
     * Set the destroy method for this definition.
     * @param methodName the name of the destroy method
     * @return the current BeanDefinitionBuilder instance (for method chaining)
     */
    public BeanDefinitionBuilder setDestroyMethodName(String methodName);
    
    /**
     * Set the scope of this definition.
     * @param scope the scope
     * @return the current BeanDefinitionBuilder instance (for method chaining)
     */
    public BeanDefinitionBuilder setScope(String scope);
    
    /**
     * Set whether this bean should be lazily initialized.
     * @param lazy whether the bean should be lazily initialized
     * @return the current BeanDefinitionBuilder instance (for method chaining)
     */
    public BeanDefinitionBuilder setLazyInit(boolean lazy);
    
    /**
     * Set whether this bean is a primary candidate.
     * @param primary whether this bean is primary
     * @return the current BeanDefinitionBuilder instance (for method chaining)
     */
    public BeanDefinitionBuilder setPrimary(boolean primary);
    
    /**
     * Set whether this bean is an autowire candidate.
     * @param autowireCandidate whether this bean is an autowire candidate
     * @return the current BeanDefinitionBuilder instance (for method chaining)
     */
    public BeanDefinitionBuilder setAutowireCandidate(boolean autowireCandidate);
    
    /**
     * Return the current BeanDefinition object in its raw (unvalidated) form.
     * @return the current BeanDefinition
     */
    public AbstractBeanDefinition getRawBeanDefinition();
    
    /**
     * Validate and return the created BeanDefinition object.
     * @return the BeanDefinition
     */
    public AbstractBeanDefinition getBeanDefinition();
}

Bean Definition Support Classes

Additional support classes for working with bean definitions.

/**
 * Abstract base class for bean definitions.
 */
abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccessor implements BeanDefinition, Cloneable {
    /** Constant for the default scope name. */
    public static final String SCOPE_DEFAULT = "";
    
    /** Constant that indicates no autowiring at all. */
    public static final int AUTOWIRE_NO = AutowireCapableBeanFactory.AUTOWIRE_NO;
    
    /** Constant that indicates autowiring bean properties by name. */
    public static final int AUTOWIRE_BY_NAME = AutowireCapableBeanFactory.AUTOWIRE_BY_NAME;
    
    /** Constant that indicates autowiring bean properties by type. */
    public static final int AUTOWIRE_BY_TYPE = AutowireCapableBeanFactory.AUTOWIRE_BY_TYPE;
    
    /** Constant that indicates autowiring the greediest constructor. */
    public static final int AUTOWIRE_CONSTRUCTOR = AutowireCapableBeanFactory.AUTOWIRE_CONSTRUCTOR;
    
    /**
     * Set the autowire mode for this bean definition.
     * @param autowireMode the autowire mode to set
     */
    public void setAutowireMode(int autowireMode);
    
    /**
     * Return the autowire mode as specified in the bean definition.
     * @return the autowire mode
     */
    public int getAutowireMode();
    
    /**
     * Set the dependency check code.
     * @param dependencyCheck the dependency check code
     */
    public void setDependencyCheck(int dependencyCheck);
    
    /**
     * Return the dependency check code.
     * @return the dependency check code
     */
    public int getDependencyCheck();
    
    /**
     * Override this bean definition from the given bean definition.
     * @param other the other bean definition
     */
    public void overrideFrom(BeanDefinition other);
    
    /**
     * Apply the provided default values to this bean.
     * @param defaults the default settings to apply
     */
    public void applyDefaults(BeanDefinitionDefaults defaults);
    
    /**
     * Return whether this definition specifies a bean class.
     * @return whether a bean class is specified
     */
    public boolean hasBeanClass();
    
    /**
     * Determine the class of the wrapped bean.
     * @param classLoader the ClassLoader to use for resolving a (potential) class name
     * @return the resolved bean class
     * @throws ClassNotFoundException if the class name could be resolved
     */
    public Class<?> resolveBeanClass(ClassLoader classLoader) throws ClassNotFoundException;
    
    /**
     * Validate this bean definition.
     * @throws BeanDefinitionValidationException in case of validation failure
     */
    public void validate() throws BeanDefinitionValidationException;
    
    /**
     * Return a deep copy of this bean definition.
     * @return the cloned bean definition object
     */
    public abstract AbstractBeanDefinition cloneBeanDefinition();
}

/**
 * Bean definition for beans that can inherit settings from their parent.
 */
class ChildBeanDefinition extends AbstractBeanDefinition {
    /**
     * Create a new ChildBeanDefinition for the given parent.
     * @param parentName the name of the parent bean
     */
    public ChildBeanDefinition(String parentName);
    
    /**
     * Create a new ChildBeanDefinition for the given parent, providing constructor arguments and property values.
     * @param parentName the name of the parent bean
     * @param cargs the constructor argument values to apply
     * @param pvs the property values to apply
     */
    public ChildBeanDefinition(String parentName, ConstructorArgumentValues cargs, MutablePropertyValues pvs);
    
    /**
     * Create a new ChildBeanDefinition for the given parent.
     * @param parentName the name of the parent bean
     * @param beanClass the class of the bean to instantiate
     */
    public ChildBeanDefinition(String parentName, Class<?> beanClass);
    
    /**
     * Create a new ChildBeanDefinition for the given parent.
     * @param parentName the name of the parent bean
     * @param beanClassName the name of the class to instantiate
     */
    public ChildBeanDefinition(String parentName, String beanClassName);
    
    /**
     * Create a new ChildBeanDefinition as deep copy of the given bean definition.
     * @param original the original bean definition to copy from
     */
    public ChildBeanDefinition(ChildBeanDefinition original);
}

/**
 * Bean definition defaults that can be applied to beans in a given context.
 */
class BeanDefinitionDefaults {
    /**
     * Return whether beans are lazy-init by default.
     * @return whether beans are lazy-init by default
     */
    public boolean isLazyInit();
    
    /**
     * Set whether beans should be lazy-init by default.
     * @param lazyInit whether beans should be lazy-init by default
     */
    public void setLazyInit(boolean lazyInit);
    
    /**
     * Return the autowire mode.
     * @return the autowire mode
     */
    public int getAutowireMode();
    
    /**
     * Set the autowire mode.
     * @param autowireMode the autowire mode
     */
    public void setAutowireMode(int autowireMode);
    
    /**
     * Return the dependency check setting.
     * @return the dependency check setting
     */
    public int getDependencyCheck();
    
    /**
     * Set the dependency check setting.
     * @param dependencyCheck the dependency check setting
     */
    public void setDependencyCheck(int dependencyCheck);
    
    /**
     * Return the name of the default init method.
     * @return the name of the default init method
     */
    public String getInitMethodName();
    
    /**
     * Set the name of the default init method.
     * @param initMethodName the name of the default init method
     */
    public void setInitMethodName(String initMethodName);
    
    /**
     * Return the name of the default destroy method.
     * @return the name of the default destroy method
     */
    public String getDestroyMethodName();
    
    /**
     * Set the name of the default destroy method.
     * @param destroyMethodName the name of the default destroy method
     */
    public void setDestroyMethodName(String destroyMethodName);
}

Bean Definition Validation and Exceptions

Exception classes for bean definition validation and processing errors.

/**
 * Exception thrown when validation of a bean definition fails.
 */
class BeanDefinitionValidationException extends BeansException {
    /**
     * Create a new BeanDefinitionValidationException with the specified message.
     * @param msg the detail message
     */
    public BeanDefinitionValidationException(String msg);
    
    /**
     * Create a new BeanDefinitionValidationException with the specified message and root cause.
     * @param msg the detail message
     * @param cause the root cause
     */
    public BeanDefinitionValidationException(String msg, Throwable cause);
}

/**
 * Exception thrown when a BeanDefinition could not be parsed.
 */
class BeanDefinitionParsingException extends BeansException {
    /**
     * Create a new BeanDefinitionParsingException.
     * @param problem the configuration problem that was detected during the parsing process
     */
    public BeanDefinitionParsingException(Problem problem);
    
    /**
     * Return an array of the Problems that were encountered during the parsing process.
     * @return the problems that were encountered during the parsing process
     */
    public Problem[] getProblems();
}

/**
 * Exception thrown when an attempt is made to override a bean definition inappropriately.
 */
class BeanDefinitionOverrideException extends BeanDefinitionStoreException {
    /**
     * Create a new BeanDefinitionOverrideException for the given new and existing definition.
     * @param beanName the name of the bean being overridden
     * @param beanDefinition the newly registered bean definition
     * @param existingDefinition the existing bean definition for the same name
     */
    public BeanDefinitionOverrideException(String beanName, BeanDefinition beanDefinition, BeanDefinition existingDefinition);
    
    /**
     * Return the description of the resource that the bean definition came from.
     * @return the description of the resource
     */
    public String getResourceDescription();
    
    /**
     * Return the name of the bean.
     * @return the name of the bean
     */
    public String getBeanName();
    
    /**
     * Return the newly registered bean definition.
     * @return the newly registered bean definition
     */
    public BeanDefinition getBeanDefinition();
    
    /**
     * Return the existing bean definition for the same name.
     * @return the existing bean definition
     */
    public BeanDefinition getExistingDefinition();
}

Install with Tessl CLI

npx tessl i tessl/maven-org-springframework--spring-beans

docs

annotation-config.md

aot-support.md

bean-definition.md

bean-factory.md

index.md

property-access.md

xml-config.md

tile.json