类 DefaultSingletonBeanRegistry

    • 字段详细资料

      • NULL_OBJECT

        protected static final Object NULL_OBJECT
        Internal marker for a null singleton object: used as marker value for concurrent Maps (which don't support null values).
      • logger

        protected final Log logger
        Logger available to subclasses
    • 方法详细资料

      • addSingleton

        protected void addSingleton​(String beanName,
                                    Object singletonObject)
        Add the given singleton object to the singleton cache of this factory.

        To be called for eager registration of singletons.

        参数:
        beanName - the name of the bean
        singletonObject - the singleton object
      • addSingletonFactory

        protected void addSingletonFactory​(String beanName,
                                           ObjectFactory<?> singletonFactory)
        Add the given singleton factory for building the specified singleton if necessary.

        To be called for eager registration of singletons, e.g. to be able to resolve circular references.

        参数:
        beanName - the name of the bean
        singletonFactory - the factory for the singleton object
      • getSingleton

        protected Object getSingleton​(String beanName,
                                      boolean allowEarlyReference)
        Return the (raw) singleton object registered under the given name.

        Checks already instantiated singletons and also allows for an early reference to a currently created singleton (resolving a circular reference).

        参数:
        beanName - the name of the bean to look for
        allowEarlyReference - whether early references should be created or not
        返回:
        the registered singleton object, or null if none found
      • getSingleton

        public Object getSingleton​(String beanName,
                                   ObjectFactory<?> singletonFactory)
        Return the (raw) singleton object registered under the given name, creating and registering a new one if none registered yet.
        参数:
        beanName - the name of the bean
        singletonFactory - the ObjectFactory to lazily create the singleton with, if necessary
        返回:
        the registered singleton object
      • onSuppressedException

        protected void onSuppressedException​(Exception ex)
        Register an Exception that happened to get suppressed during the creation of a singleton bean instance, e.g. a temporary circular reference resolution problem.
        参数:
        ex - the Exception to register
      • removeSingleton

        protected void removeSingleton​(String beanName)
        Remove the bean with the given name from the singleton cache of this factory, to be able to clean up eager registration of a singleton if creation failed.
        参数:
        beanName - the name of the bean
        另请参阅:
        getSingletonMutex()
      • isSingletonCurrentlyInCreation

        public boolean isSingletonCurrentlyInCreation​(String beanName)
        Return whether the specified singleton bean is currently in creation (within the entire factory).
        参数:
        beanName - the name of the bean
      • registerDisposableBean

        public void registerDisposableBean​(String beanName,
                                           DisposableBean bean)
        Add the given bean to the list of disposable beans in this registry.

        Disposable beans usually correspond to registered singletons, matching the bean name but potentially being a different instance (for example, a DisposableBean adapter for a singleton that does not naturally implement Spring's DisposableBean interface).

        参数:
        beanName - the name of the bean
        bean - the bean instance
      • registerContainedBean

        public void registerContainedBean​(String containedBeanName,
                                          String containingBeanName)
        Register a containment relationship between two beans, e.g. between an inner bean and its containing outer bean.

        Also registers the containing bean as dependent on the contained bean in terms of destruction order.

        参数:
        containedBeanName - the name of the contained (inner) bean
        containingBeanName - the name of the containing (outer) bean
        另请参阅:
        registerDependentBean(java.lang.String, java.lang.String)
      • registerDependentBean

        public void registerDependentBean​(String beanName,
                                          String dependentBeanName)
        Register a dependent bean for the given bean, to be destroyed before the given bean is destroyed.
        参数:
        beanName - the name of the bean
        dependentBeanName - the name of the dependent bean
      • isDependent

        protected boolean isDependent​(String beanName,
                                      String dependentBeanName)
        Determine whether the specified dependent bean has been registered as dependent on the given bean or on any of its transitive dependencies.
        参数:
        beanName - the name of the bean to check
        dependentBeanName - the name of the dependent bean
        从以下版本开始:
        4.0
      • hasDependentBean

        protected boolean hasDependentBean​(String beanName)
        Determine whether a dependent bean has been registered for the given name.
        参数:
        beanName - the name of the bean to check
      • getDependentBeans

        public String[] getDependentBeans​(String beanName)
        Return the names of all beans which depend on the specified bean, if any.
        参数:
        beanName - the name of the bean
        返回:
        the array of dependent bean names, or an empty array if none
      • getDependenciesForBean

        public String[] getDependenciesForBean​(String beanName)
        Return the names of all beans that the specified bean depends on, if any.
        参数:
        beanName - the name of the bean
        返回:
        the array of names of beans which the bean depends on, or an empty array if none
      • clearSingletonCache

        protected void clearSingletonCache()
        Clear all cached singleton instances in this registry.
        从以下版本开始:
        4.3.15
      • destroyBean

        protected void destroyBean​(String beanName,
                                   DisposableBean bean)
        Destroy the given bean. Must destroy beans that depend on the given bean before the bean itself. Should not throw any exceptions.
        参数:
        beanName - the name of the bean
        bean - the bean instance to destroy
      • getSingletonMutex

        public final Object getSingletonMutex()
        Exposes the singleton mutex to subclasses and external collaborators.

        Subclasses should synchronize on the given Object if they perform any sort of extended singleton creation phase. In particular, subclasses should not have their own mutexes involved in singleton creation, to avoid the potential for deadlocks in lazy-init situations.

        指定者:
        getSingletonMutex 在接口中 SingletonBeanRegistry
        返回:
        the mutex object (never null)