Class ApplicationContextAwareFactoryBean<T>

  • Type Parameters:
    T - - type of bean
    All Implemented Interfaces:
    org.springframework.beans.factory.Aware, org.springframework.beans.factory.FactoryBean<T>, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationContextAware

    public abstract class ApplicationContextAwareFactoryBean<T>
    extends java.lang.Object
    implements org.springframework.beans.factory.FactoryBean<T>, org.springframework.context.ApplicationContextAware, org.springframework.beans.factory.InitializingBean
    FactoryBean with access to ApplicationContext with lazy initialization
    • Field Summary

      • Fields inherited from interface org.springframework.beans.factory.FactoryBean

        OBJECT_TYPE_ATTRIBUTE
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void afterPropertiesSet()
      Instantiates supplier for bean to be created.
      protected abstract T createInstance()
      Template method that subclasses must override to construct the object returned by this factory.
      protected org.springframework.context.ApplicationContext getApplicationContext()  
      T getObject()  
      boolean isSingleton()  
      void setApplicationContext​(org.springframework.context.ApplicationContext applicationContext)  
      void setSingleton​(boolean singleton)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.springframework.beans.factory.FactoryBean

        getObjectType
    • Constructor Detail

      • ApplicationContextAwareFactoryBean

        public ApplicationContextAwareFactoryBean()
    • Method Detail

      • setApplicationContext

        public void setApplicationContext​(org.springframework.context.ApplicationContext applicationContext)
                                   throws org.springframework.beans.BeansException
        Specified by:
        setApplicationContext in interface org.springframework.context.ApplicationContextAware
        Throws:
        org.springframework.beans.BeansException
      • getObject

        public T getObject()
                    throws java.lang.Exception
        Specified by:
        getObject in interface org.springframework.beans.factory.FactoryBean<T>
        Throws:
        java.lang.Exception
      • isSingleton

        public boolean isSingleton()
        Specified by:
        isSingleton in interface org.springframework.beans.factory.FactoryBean<T>
      • setSingleton

        public void setSingleton​(boolean singleton)
      • afterPropertiesSet

        public void afterPropertiesSet()
                                throws java.lang.Exception
        Instantiates supplier for bean to be created. This mades possible lazy-initialization
        Specified by:
        afterPropertiesSet in interface org.springframework.beans.factory.InitializingBean
        Throws:
        java.lang.Exception
      • getApplicationContext

        protected org.springframework.context.ApplicationContext getApplicationContext()
      • createInstance

        protected abstract T createInstance()
        Template method that subclasses must override to construct the object returned by this factory.

        Invoked on initialization of this FactoryBean in case of a singleton; else, on each getObject() call.

        Returns:
        the object returned by this factory
        See Also:
        getObject()