org.springframework.beans.factory.support

Class AbstractBeanFactory

    • Constructor Detail

      • AbstractBeanFactory

        public AbstractBeanFactory()
        Create a new AbstractBeanFactory.
      • AbstractBeanFactory

        public AbstractBeanFactory(@Nullable
                                   BeanFactory parentBeanFactory)
        Create a new AbstractBeanFactory with the given parent.
        Parameters:
        parentBeanFactory - parent bean factory, or null if none
        See Also:
        getBean(java.lang.String)
    • Method Detail

      • getBean

        public java.lang.Object getBean(java.lang.String name)
                                 throws BeansException
        Description copied from interface: BeanFactory
        Return an instance, which may be shared or independent, of the specified bean.

        This method allows a Spring BeanFactory to be used as a replacement for the Singleton or Prototype design pattern. Callers may retain references to returned objects in the case of Singleton beans.

        Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.

        Specified by:
        getBean in interface BeanFactory
        Parameters:
        name - the name of the bean to retrieve
        Returns:
        an instance of the bean
        Throws:
        NoSuchBeanDefinitionException - if there is no bean definition with the specified name
        BeansException - if the bean could not be obtained
      • getBean

        public <T> T getBean(java.lang.String name,
                             java.lang.Class<T> requiredType)
                      throws BeansException
        Description copied from interface: BeanFactory
        Return an instance, which may be shared or independent, of the specified bean.

        Behaves the same as BeanFactory.getBean(String), but provides a measure of type safety by throwing a BeanNotOfRequiredTypeException if the bean is not of the required type. This means that ClassCastException can't be thrown on casting the result correctly, as can happen with BeanFactory.getBean(String).

        Translates aliases back to the corresponding canonical bean name. Will ask the parent factory if the bean cannot be found in this factory instance.

        Specified by:
        getBean in interface BeanFactory
        Parameters:
        name - the name of the bean to retrieve
        requiredType - type the bean must match; can be an interface or superclass
        Returns:
        an instance of the bean
        Throws:
        NoSuchBeanDefinitionException - if there is no such bean definition
        BeanNotOfRequiredTypeException - if the bean is not of the required type
        BeansException - if the bean could not be created
      • getBean

        public java.lang.Object getBean(java.lang.String name,
                                        java.lang.Object... args)
                                 throws BeansException
        Description copied from interface: BeanFactory
        Return an instance, which may be shared or independent, of the specified bean.

        Allows for specifying explicit constructor arguments / factory method arguments, overriding the specified default arguments (if any) in the bean definition.

        Specified by:
        getBean in interface BeanFactory
        Parameters:
        name - the name of the bean to retrieve
        args - arguments to use when creating a bean instance using explicit arguments (only applied when creating a new instance as opposed to retrieving an existing one)
        Returns:
        an instance of the bean
        Throws:
        NoSuchBeanDefinitionException - if there is no such bean definition
        BeanDefinitionStoreException - if arguments have been given but the affected bean isn't a prototype
        BeansException - if the bean could not be created
      • getBean

        public <T> T getBean(java.lang.String name,
                             @Nullable
                             java.lang.Class<T> requiredType,
                             @Nullable
                             java.lang.Object... args)
                      throws BeansException
        Return an instance, which may be shared or independent, of the specified bean.
        Parameters:
        name - the name of the bean to retrieve
        requiredType - the required type of the bean to retrieve
        args - arguments to use when creating a bean instance using explicit arguments (only applied when creating a new instance as opposed to retrieving an existing one)
        Returns:
        an instance of the bean
        Throws:
        BeansException - if the bean could not be created
      • doGetBean

        protected <T> T doGetBean(java.lang.String name,
                                  @Nullable
                                  java.lang.Class<T> requiredType,
                                  @Nullable
                                  java.lang.Object[] args,
                                  boolean typeCheckOnly)
                           throws BeansException
        Return an instance, which may be shared or independent, of the specified bean.
        Parameters:
        name - the name of the bean to retrieve
        requiredType - the required type of the bean to retrieve
        args - arguments to use when creating a bean instance using explicit arguments (only applied when creating a new instance as opposed to retrieving an existing one)
        typeCheckOnly - whether the instance is obtained for a type check, not for actual use
        Returns:
        an instance of the bean
        Throws:
        BeansException - if the bean could not be created
      • containsBean

        public boolean containsBean(java.lang.String name)
        Description copied from interface: BeanFactory
        Does this bean factory contain a bean definition or externally registered singleton instance with the given name?

        If the given name is an alias, it will be translated back to the corresponding canonical bean name.

        If this factory is hierarchical, will ask any parent factory if the bean cannot be found in this factory instance.

        If a bean definition or singleton instance matching the given name is found, this method will return true whether the named bean definition is concrete or abstract, lazy or eager, in scope or not. Therefore, note that a true return value from this method does not necessarily indicate that BeanFactory.getBean(java.lang.String) will be able to obtain an instance for the same name.

        Specified by:
        containsBean in interface BeanFactory
        Parameters:
        name - the name of the bean to query
        Returns:
        whether a bean with the given name is present
      • containsLocalBean

        public boolean containsLocalBean(java.lang.String name)
        Description copied from interface: HierarchicalBeanFactory
        Return whether the local bean factory contains a bean of the given name, ignoring beans defined in ancestor contexts.

        This is an alternative to containsBean, ignoring a bean of the given name from an ancestor bean factory.

        Specified by:
        containsLocalBean in interface HierarchicalBeanFactory
        Parameters:
        name - the name of the bean to query
        Returns:
        whether a bean with the given name is defined in the local factory
        See Also:
        BeanFactory.containsBean(java.lang.String)
      • setBeanClassLoader

        public void setBeanClassLoader(@Nullable
                                       java.lang.ClassLoader beanClassLoader)
        Description copied from interface: ConfigurableBeanFactory
        Set the class loader to use for loading bean classes. Default is the thread context class loader.

        Note that this class loader will only apply to bean definitions that do not carry a resolved bean class yet. This is the case as of Spring 2.0 by default: Bean definitions only carry bean class names, to be resolved once the factory processes the bean definition.

        Specified by:
        setBeanClassLoader in interface ConfigurableBeanFactory
        Parameters:
        beanClassLoader - the class loader to use, or null to suggest the default class loader
      • setTempClassLoader

        public void setTempClassLoader(@Nullable
                                       java.lang.ClassLoader tempClassLoader)
        Description copied from interface: ConfigurableBeanFactory
        Specify a temporary ClassLoader to use for type matching purposes. Default is none, simply using the standard bean ClassLoader.

        A temporary ClassLoader is usually just specified if load-time weaving is involved, to make sure that actual bean classes are loaded as lazily as possible. The temporary loader is then removed once the BeanFactory completes its bootstrap phase.

        Specified by:
        setTempClassLoader in interface ConfigurableBeanFactory
      • setCacheBeanMetadata

        public void setCacheBeanMetadata(boolean cacheBeanMetadata)
        Description copied from interface: ConfigurableBeanFactory
        Set whether to cache bean metadata such as given bean definitions (in merged fashion) and resolved bean classes. Default is on.

        Turn this flag off to enable hot-refreshing of bean definition objects and in particular bean classes. If this flag is off, any creation of a bean instance will re-query the bean class loader for newly resolved classes.

        Specified by:
        setCacheBeanMetadata in interface ConfigurableBeanFactory
      • setBeanExpressionResolver

        public void setBeanExpressionResolver(@Nullable
                                              BeanExpressionResolver resolver)
        Description copied from interface: ConfigurableBeanFactory
        Specify the resolution strategy for expressions in bean definition values.

        There is no expression support active in a BeanFactory by default. An ApplicationContext will typically set a standard expression strategy here, supporting "#{...}" expressions in a Unified EL compatible style.

        Specified by:
        setBeanExpressionResolver in interface ConfigurableBeanFactory
      • getPropertyEditorRegistrars

        public java.util.Set<PropertyEditorRegistrar> getPropertyEditorRegistrars()
        Return the set of PropertyEditorRegistrars.
      • registerCustomEditor

        public void registerCustomEditor(java.lang.Class<?> requiredType,
                                         java.lang.Class<? extends java.beans.PropertyEditor> propertyEditorClass)
        Description copied from interface: ConfigurableBeanFactory
        Register the given custom property editor for all properties of the given type. To be invoked during factory configuration.

        Note that this method will register a shared custom editor instance; access to that instance will be synchronized for thread-safety. It is generally preferable to use ConfigurableBeanFactory.addPropertyEditorRegistrar(org.springframework.beans.PropertyEditorRegistrar) instead of this method, to avoid for the need for synchronization on custom editors.

        Specified by:
        registerCustomEditor in interface ConfigurableBeanFactory
        Parameters:
        requiredType - type of the property
        propertyEditorClass - the PropertyEditor class to register
      • getCustomEditors

        public java.util.Map<java.lang.Class<?>,java.lang.Class<? extends java.beans.PropertyEditor>> getCustomEditors()
        Return the map of custom editors, with Classes as keys and PropertyEditor classes as values.
      • getCustomTypeConverter

        @Nullable
        protected TypeConverter getCustomTypeConverter()
        Return the custom TypeConverter to use, if any.
        Returns:
        the custom TypeConverter, or null if none specified
      • getTypeConverter

        public TypeConverter getTypeConverter()
        Description copied from interface: ConfigurableBeanFactory
        Obtain a type converter as used by this BeanFactory. This may be a fresh instance for each call, since TypeConverters are usually not thread-safe.

        If the default PropertyEditor mechanism is active, the returned TypeConverter will be aware of all custom editors that have been registered.

        Specified by:
        getTypeConverter in interface ConfigurableBeanFactory
      • addBeanPostProcessor

        public void addBeanPostProcessor(BeanPostProcessor beanPostProcessor)
        Description copied from interface: ConfigurableBeanFactory
        Add a new BeanPostProcessor that will get applied to beans created by this factory. To be invoked during factory configuration.

        Note: Post-processors submitted here will be applied in the order of registration; any ordering semantics expressed through implementing the Ordered interface will be ignored. Note that autodetected post-processors (e.g. as beans in an ApplicationContext) will always be applied after programmatically registered ones.

        Specified by:
        addBeanPostProcessor in interface ConfigurableBeanFactory
        Parameters:
        beanPostProcessor - the post-processor to register
      • getBeanPostProcessors

        public java.util.List<BeanPostProcessor> getBeanPostProcessors()
        Return the list of BeanPostProcessors that will get applied to beans created with this factory.
      • registerScope

        public void registerScope(java.lang.String scopeName,
                                  Scope scope)
        Description copied from interface: ConfigurableBeanFactory
        Register the given scope, backed by the given Scope implementation.
        Specified by:
        registerScope in interface ConfigurableBeanFactory
        Parameters:
        scopeName - the scope identifier
        scope - the backing Scope implementation
      • setSecurityContextProvider

        public void setSecurityContextProvider(SecurityContextProvider securityProvider)
        Set the security context provider for this bean factory. If a security manager is set, interaction with the user code will be executed using the privileged of the provided security context.
      • copyConfigurationFrom

        public void copyConfigurationFrom(ConfigurableBeanFactory otherFactory)
        Description copied from interface: ConfigurableBeanFactory
        Copy all relevant configuration from the given other factory.

        Should include all standard configuration settings as well as BeanPostProcessors, Scopes, and factory-specific internal settings. Should not include any metadata of actual bean definitions, such as BeanDefinition objects and bean name aliases.

        Specified by:
        copyConfigurationFrom in interface ConfigurableBeanFactory
        Parameters:
        otherFactory - the other BeanFactory to copy from
      • isPrototypeCurrentlyInCreation

        protected boolean isPrototypeCurrentlyInCreation(java.lang.String beanName)
        Return whether the specified prototype bean is currently in creation (within the current thread).
        Parameters:
        beanName - the name of the bean
      • beforePrototypeCreation

        protected void beforePrototypeCreation(java.lang.String beanName)
        Callback before prototype creation.

        The default implementation register the prototype as currently in creation.

        Parameters:
        beanName - the name of the prototype about to be created
        See Also:
        isPrototypeCurrentlyInCreation(java.lang.String)
      • afterPrototypeCreation

        protected void afterPrototypeCreation(java.lang.String beanName)
        Callback after prototype creation.

        The default implementation marks the prototype as not in creation anymore.

        Parameters:
        beanName - the name of the prototype that has been created
        See Also:
        isPrototypeCurrentlyInCreation(java.lang.String)
      • destroyBean

        public void destroyBean(java.lang.String beanName,
                                java.lang.Object beanInstance)
        Description copied from interface: ConfigurableBeanFactory
        Destroy the given bean instance (usually a prototype instance obtained from this factory) according to its bean definition.

        Any exception that arises during destruction should be caught and logged instead of propagated to the caller of this method.

        Specified by:
        destroyBean in interface ConfigurableBeanFactory
        Parameters:
        beanName - the name of the bean definition
        beanInstance - the bean instance to destroy
      • destroyBean

        protected void destroyBean(java.lang.String beanName,
                                   java.lang.Object bean,
                                   RootBeanDefinition mbd)
        Destroy the given bean instance (usually a prototype instance obtained from this factory) according to the given bean definition.
        Parameters:
        beanName - the name of the bean definition
        bean - the bean instance to destroy
        mbd - the merged bean definition
      • destroyScopedBean

        public void destroyScopedBean(java.lang.String beanName)
        Description copied from interface: ConfigurableBeanFactory
        Destroy the specified scoped bean in the current target scope, if any.

        Any exception that arises during destruction should be caught and logged instead of propagated to the caller of this method.

        Specified by:
        destroyScopedBean in interface ConfigurableBeanFactory
        Parameters:
        beanName - the name of the scoped bean
      • transformedBeanName

        protected java.lang.String transformedBeanName(java.lang.String name)
        Return the bean name, stripping out the factory dereference prefix if necessary, and resolving aliases to canonical names.
        Parameters:
        name - the user-specified name
        Returns:
        the transformed bean name
      • originalBeanName

        protected java.lang.String originalBeanName(java.lang.String name)
        Determine the original bean name, resolving locally defined aliases to canonical names.
        Parameters:
        name - the user-specified name
        Returns:
        the original bean name
      • initBeanWrapper

        protected void initBeanWrapper(BeanWrapper bw)
        Initialize the given BeanWrapper with the custom editors registered with this factory. To be called for BeanWrappers that will create and populate bean instances.

        The default implementation delegates to registerCustomEditors(org.springframework.beans.PropertyEditorRegistry). Can be overridden in subclasses.

        Parameters:
        bw - the BeanWrapper to initialize
      • registerCustomEditors

        protected void registerCustomEditors(PropertyEditorRegistry registry)
        Initialize the given PropertyEditorRegistry with the custom editors that have been registered with this BeanFactory.

        To be called for BeanWrappers that will create and populate bean instances, and for SimpleTypeConverter used for constructor argument and factory method type conversion.

        Parameters:
        registry - the PropertyEditorRegistry to initialize
      • getMergedLocalBeanDefinition

        protected RootBeanDefinition getMergedLocalBeanDefinition(java.lang.String beanName)
                                                           throws BeansException
        Return a merged RootBeanDefinition, traversing the parent bean definition if the specified bean corresponds to a child bean definition.
        Parameters:
        beanName - the name of the bean to retrieve the merged definition for
        Returns:
        a (potentially merged) RootBeanDefinition for the given bean
        Throws:
        NoSuchBeanDefinitionException - if there is no bean with the given name
        BeanDefinitionStoreException - in case of an invalid bean definition
        BeansException
      • getMergedBeanDefinition

        protected RootBeanDefinition getMergedBeanDefinition(java.lang.String beanName,
                                                             BeanDefinition bd)
                                                      throws BeanDefinitionStoreException
        Return a RootBeanDefinition for the given top-level bean, by merging with the parent if the given bean's definition is a child bean definition.
        Parameters:
        beanName - the name of the bean definition
        bd - the original bean definition (Root/ChildBeanDefinition)
        Returns:
        a (potentially merged) RootBeanDefinition for the given bean
        Throws:
        BeanDefinitionStoreException - in case of an invalid bean definition
      • getMergedBeanDefinition

        protected RootBeanDefinition getMergedBeanDefinition(java.lang.String beanName,
                                                             BeanDefinition bd,
                                                             @Nullable
                                                             BeanDefinition containingBd)
                                                      throws BeanDefinitionStoreException
        Return a RootBeanDefinition for the given bean, by merging with the parent if the given bean's definition is a child bean definition.
        Parameters:
        beanName - the name of the bean definition
        bd - the original bean definition (Root/ChildBeanDefinition)
        containingBd - the containing bean definition in case of inner bean, or null in case of a top-level bean
        Returns:
        a (potentially merged) RootBeanDefinition for the given bean
        Throws:
        BeanDefinitionStoreException - in case of an invalid bean definition
      • checkMergedBeanDefinition

        protected void checkMergedBeanDefinition(RootBeanDefinition mbd,
                                                 java.lang.String beanName,
                                                 @Nullable
                                                 java.lang.Object[] args)
                                          throws BeanDefinitionStoreException
        Check the given merged bean definition, potentially throwing validation exceptions.
        Parameters:
        mbd - the merged bean definition to check
        beanName - the name of the bean
        args - the arguments for bean creation, if any
        Throws:
        BeanDefinitionStoreException - in case of validation failure
      • clearMergedBeanDefinition

        protected void clearMergedBeanDefinition(java.lang.String beanName)
        Remove the merged bean definition for the specified bean, recreating it on next access.
        Parameters:
        beanName - the bean name to clear the merged definition for
      • clearMetadataCache

        public void clearMetadataCache()
        Clear the merged bean definition cache, removing entries for beans which are not considered eligible for full metadata caching yet.

        Typically triggered after changes to the original bean definitions, e.g. after applying a BeanFactoryPostProcessor. Note that metadata for beans which have already been created at this point will be kept around.

        Since:
        4.2
      • resolveBeanClass

        @Nullable
        protected java.lang.Class<?> resolveBeanClass(RootBeanDefinition mbd,
                                                                java.lang.String beanName,
                                                                java.lang.Class<?>... typesToMatch)
                                                         throws CannotLoadBeanClassException
        Resolve the bean class for the specified bean definition, resolving a bean class name into a Class reference (if necessary) and storing the resolved Class in the bean definition for further use.
        Parameters:
        mbd - the merged bean definition to determine the class for
        beanName - the name of the bean (for error handling purposes)
        typesToMatch - the types to match in case of internal type matching purposes (also signals that the returned Class will never be exposed to application code)
        Returns:
        the resolved bean class (or null if none)
        Throws:
        CannotLoadBeanClassException - if we failed to load the class
      • predictBeanType

        @Nullable
        protected java.lang.Class<?> predictBeanType(java.lang.String beanName,
                                                               RootBeanDefinition mbd,
                                                               java.lang.Class<?>... typesToMatch)
        Predict the eventual bean type (of the processed bean instance) for the specified bean. Called by getType(java.lang.String) and isTypeMatch(java.lang.String, org.springframework.core.ResolvableType). Does not need to handle FactoryBeans specifically, since it is only supposed to operate on the raw bean type.

        This implementation is simplistic in that it is not able to handle factory methods and InstantiationAwareBeanPostProcessors. It only predicts the bean type correctly for a standard bean. To be overridden in subclasses, applying more sophisticated type detection.

        Parameters:
        beanName - the name of the bean
        mbd - the merged bean definition to determine the type for
        typesToMatch - the types to match in case of internal type matching purposes (also signals that the returned Class will never be exposed to application code)
        Returns:
        the type of the bean, or null if not predictable
      • isFactoryBean

        protected boolean isFactoryBean(java.lang.String beanName,
                                        RootBeanDefinition mbd)
        Check whether the given bean is defined as a FactoryBean.
        Parameters:
        beanName - the name of the bean
        mbd - the corresponding bean definition
      • getTypeForFactoryBean

        @Nullable
        protected java.lang.Class<?> getTypeForFactoryBean(java.lang.String beanName,
                                                                     RootBeanDefinition mbd)
        Determine the bean type for the given FactoryBean definition, as far as possible. Only called if there is no singleton instance registered for the target bean already.

        The default implementation creates the FactoryBean via getBean to call its getObjectType method. Subclasses are encouraged to optimize this, typically by just instantiating the FactoryBean but not populating it yet, trying whether its getObjectType method already returns a type. If no type found, a full FactoryBean creation as performed by this implementation should be used as fallback.

        Parameters:
        beanName - the name of the bean
        mbd - the merged bean definition for the bean
        Returns:
        the type for the bean if determinable, or null otherwise
        See Also:
        FactoryBean.getObjectType(), getBean(String)
      • markBeanAsCreated

        protected void markBeanAsCreated(java.lang.String beanName)
        Mark the specified bean as already created (or about to be created).

        This allows the bean factory to optimize its caching for repeated creation of the specified bean.

        Parameters:
        beanName - the name of the bean
      • cleanupAfterBeanCreationFailure

        protected void cleanupAfterBeanCreationFailure(java.lang.String beanName)
        Perform appropriate cleanup of cached metadata after bean creation failed.
        Parameters:
        beanName - the name of the bean
      • isBeanEligibleForMetadataCaching

        protected boolean isBeanEligibleForMetadataCaching(java.lang.String beanName)
        Determine whether the specified bean is eligible for having its bean definition metadata cached.
        Parameters:
        beanName - the name of the bean
        Returns:
        true if the bean's metadata may be cached at this point already
      • removeSingletonIfCreatedForTypeCheckOnly

        protected boolean removeSingletonIfCreatedForTypeCheckOnly(java.lang.String beanName)
        Remove the singleton instance (if any) for the given bean name, but only if it hasn't been used for other purposes than type checking.
        Parameters:
        beanName - the name of the bean
        Returns:
        true if actually removed, false otherwise
      • hasBeanCreationStarted

        protected boolean hasBeanCreationStarted()
        Check whether this factory's bean creation phase already started, i.e. whether any bean has been marked as created in the meantime.
        Since:
        4.2.2
        See Also:
        markBeanAsCreated(java.lang.String)
      • getObjectForBeanInstance

        protected java.lang.Object getObjectForBeanInstance(java.lang.Object beanInstance,
                                                            java.lang.String name,
                                                            java.lang.String beanName,
                                                            @Nullable
                                                            RootBeanDefinition mbd)
        Get the object for the given bean instance, either the bean instance itself or its created object in case of a FactoryBean.
        Parameters:
        beanInstance - the shared bean instance
        name - name that may include factory dereference prefix
        beanName - the canonical bean name
        mbd - the merged bean definition
        Returns:
        the object to expose for the bean
      • isBeanNameInUse

        public boolean isBeanNameInUse(java.lang.String beanName)
        Determine whether the given bean name is already in use within this factory, i.e. whether there is a local bean or alias registered under this name or an inner bean created with this name.
        Parameters:
        beanName - the name to check
      • containsBeanDefinition

        protected abstract boolean containsBeanDefinition(java.lang.String beanName)
        Check if this bean factory contains a bean definition with the given name. Does not consider any hierarchy this factory may participate in. Invoked by containsBean when no cached singleton instance is found.

        Depending on the nature of the concrete bean factory implementation, this operation might be expensive (for example, because of directory lookups in external registries). However, for listable bean factories, this usually just amounts to a local hash lookup: The operation is therefore part of the public interface there. The same implementation can serve for both this template method and the public interface method in that case.

        Parameters:
        beanName - the name of the bean to look for
        Returns:
        if this bean factory contains a bean definition with the given name
        See Also:
        containsBean(java.lang.String), ListableBeanFactory.containsBeanDefinition(java.lang.String)
      • getBeanDefinition

        protected abstract BeanDefinition getBeanDefinition(java.lang.String beanName)
                                                     throws BeansException
        Return the bean definition for the given bean name. Subclasses should normally implement caching, as this method is invoked by this class every time bean definition metadata is needed.

        Depending on the nature of the concrete bean factory implementation, this operation might be expensive (for example, because of directory lookups in external registries). However, for listable bean factories, this usually just amounts to a local hash lookup: The operation is therefore part of the public interface there. The same implementation can serve for both this template method and the public interface method in that case.

        Parameters:
        beanName - the name of the bean to find a definition for
        Returns:
        the BeanDefinition for this prototype name (never null)
        Throws:
        NoSuchBeanDefinitionException - if the bean definition cannot be resolved
        BeansException - in case of errors
        See Also:
        RootBeanDefinition, ChildBeanDefinition, ConfigurableListableBeanFactory.getBeanDefinition(java.lang.String)
      • createBean

        protected abstract java.lang.Object createBean(java.lang.String beanName,
                                                       RootBeanDefinition mbd,
                                                       @Nullable
                                                       java.lang.Object[] args)
                                                throws BeanCreationException
        Create a bean instance for the given merged bean definition (and arguments). The bean definition will already have been merged with the parent definition in case of a child definition.

        All bean retrieval methods delegate to this method for actual bean creation.

        Parameters:
        beanName - the name of the bean
        mbd - the merged bean definition for the bean
        args - explicit arguments to use for constructor or factory method invocation
        Returns:
        a new instance of the bean
        Throws:
        BeanCreationException - if the bean could not be created