Class DependentAnnotationConfigApplicationContext

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, org.springframework.beans.factory.BeanFactory, org.springframework.beans.factory.HierarchicalBeanFactory, org.springframework.beans.factory.ListableBeanFactory, org.springframework.beans.factory.support.BeanDefinitionRegistry, org.springframework.context.annotation.AnnotationConfigRegistry, org.springframework.context.ApplicationContext, org.springframework.context.ApplicationEventPublisher, org.springframework.context.ConfigurableApplicationContext, org.springframework.context.Lifecycle, org.springframework.context.MessageSource, org.springframework.core.AliasRegistry, org.springframework.core.env.EnvironmentCapable, org.springframework.core.io.ResourceLoader, org.springframework.core.io.support.ResourcePatternResolver

    public class DependentAnnotationConfigApplicationContext
    extends org.springframework.context.annotation.AnnotationConfigApplicationContext
    Standalone application context that enhances the standard standalone application context by allowing to register and scan for beans that are lazy instantiated dependent on the creation of another bean. Meaning the creation of BeanA triggers the instantiation of all beans that are annotated with @DependentInitialisation(BeanA.class).
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.springframework.core.io.DefaultResourceLoader

        org.springframework.core.io.DefaultResourceLoader.ClassPathContextResource
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addFile​(java.io.File f)  
      (package private) void addPluginsToClasspath()  
      private void addURL​(java.net.URL u)  
      (package private) <T> java.util.List<T> findAllPrototypeBeans​(java.lang.Class<T> type)  
      <T> T getBean​(java.lang.Class<T> requiredType)  
      <T> T getBean​(java.lang.Class<T> requiredType, java.lang.Object... args)  
      java.lang.Object getBean​(java.lang.String name)  
      <T> T getBean​(java.lang.String name, java.lang.Class<T> requiredType)  
      java.lang.Object getBean​(java.lang.String name, java.lang.Object... args)  
      <T> java.lang.String getBeanNameByType​(java.lang.Class<T> requiredType)  
      java.util.List<java.lang.Object> getBeans​(java.lang.Class beanType)
      Retrieve a list of all property beans of a given type.
      private org.springframework.core.type.StandardMethodMetadata getMetadataFromConfiguration​(org.springframework.beans.factory.config.BeanDefinition beanDef)  
      private org.springframework.core.type.AnnotationMetadata getMetadataFromScannedBean​(org.springframework.beans.factory.config.BeanDefinition beanDef)  
      java.util.List<java.lang.Object> getPrototypeBeans()  
      protected void invokeBeanFactoryPostProcessors​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)  
      <T> boolean isBeanInstantiated​(java.lang.Class<T> requiredType)
      Check if a bean with the matching type is instantiated.
      <T> boolean isBeanInstantiated​(java.lang.Class<T> requiredType, java.lang.Object... constructorArgs)
      Check if a bean with the matching type and constructor is instantiated.
      boolean isBeanInstantiated​(java.lang.String beanName)
      Check if a bean with the matching name is instantiated.
      private boolean isBeanInstantiated​(java.lang.String[] beanNames, java.lang.Object... constructorArgs)  
      boolean isBeanInstantiated​(java.lang.String beanName, java.lang.Object... constructorArgs)
      Check if a bean with the matching type and constructor is instantiated.
      private void registerBeansFromComponentScan​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, org.springframework.beans.factory.config.BeanDefinition beanDef)  
      private void registerBeansFromConfiguration​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory, org.springframework.beans.factory.config.BeanDefinition beanDef)  
      protected void registerDependentBeanInitialisation​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)  
      <T> void removePrototypeBean​(T beanToBeRemoved)
      Remove the bean from the context.
      <T> boolean replaceBean​(T bean, T originalBean, java.util.Set<IRebinabable> rebindableObjects)
      Replace the originalBean with bean.
      <T> void replacePropertyBeans​(java.util.List<javafx.util.Pair<java.lang.String,​T>> newBeans)
      Remove all prototype beans of type T and put the beans in the list in instead.
      • Methods inherited from class org.springframework.context.annotation.AnnotationConfigApplicationContext

        register, registerBean, registerBean, registerBean, scan, setBeanNameGenerator, setEnvironment, setScopeMetadataResolver
      • Methods inherited from class org.springframework.context.support.GenericApplicationContext

        cancelRefresh, closeBeanFactory, getAutowireCapableBeanFactory, getBeanDefinition, getBeanFactory, getClassLoader, getDefaultListableBeanFactory, getResource, getResources, isAlias, isBeanNameInUse, refreshBeanFactory, registerAlias, registerBean, registerBean, registerBean, registerBeanDefinition, removeAlias, removeBeanDefinition, setAllowBeanDefinitionOverriding, setAllowCircularReferences, setClassLoader, setParent, setResourceLoader
      • Methods inherited from class org.springframework.context.support.AbstractApplicationContext

        addApplicationListener, addBeanFactoryPostProcessor, assertBeanFactoryActive, close, containsBean, containsBeanDefinition, containsLocalBean, createEnvironment, destroy, destroyBeans, doClose, findAnnotationOnBean, finishBeanFactoryInitialization, finishRefresh, getAliases, getApplicationListeners, getApplicationName, getBeanDefinitionCount, getBeanDefinitionNames, getBeanFactoryPostProcessors, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanProvider, getBeanProvider, getBeansOfType, getBeansOfType, getBeansWithAnnotation, getDisplayName, getEnvironment, getId, getInternalParentBeanFactory, getInternalParentMessageSource, getMessage, getMessage, getMessage, getParent, getParentBeanFactory, getResourcePatternResolver, getStartupDate, getType, initApplicationEventMulticaster, initLifecycleProcessor, initMessageSource, initPropertySources, isActive, isPrototype, isRunning, isSingleton, isTypeMatch, isTypeMatch, obtainFreshBeanFactory, onClose, onRefresh, postProcessBeanFactory, prepareBeanFactory, prepareRefresh, publishEvent, publishEvent, publishEvent, refresh, registerBeanPostProcessors, registerListeners, registerShutdownHook, resetCommonCaches, setDisplayName, setId, start, stop, toString
      • Methods inherited from class org.springframework.core.io.DefaultResourceLoader

        addProtocolResolver, clearResourceCaches, getProtocolResolvers, getResourceByPath, getResourceCache
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
      • Methods inherited from interface org.springframework.core.AliasRegistry

        getAliases
      • Methods inherited from interface org.springframework.beans.factory.support.BeanDefinitionRegistry

        containsBeanDefinition, getBeanDefinitionCount, getBeanDefinitionNames
      • Methods inherited from interface org.springframework.context.ConfigurableApplicationContext

        addProtocolResolver
    • Constructor Detail

      • DependentAnnotationConfigApplicationContext

        DependentAnnotationConfigApplicationContext()
        Create a new DependentAnnotationConfigApplicationContext that needs to be populated through AnnotationConfigApplicationContext.register(java.lang.Class<?>...) calls and then manually refreshed.
      • DependentAnnotationConfigApplicationContext

        protected DependentAnnotationConfigApplicationContext​(AutowireCapableBeanFactory beanFactory)
        Create a new AnnotationConfigApplicationContext with the given DefaultListableBeanFactory.
        Parameters:
        beanFactory - the DefaultListableBeanFactory instance to use for this context
      • DependentAnnotationConfigApplicationContext

        public DependentAnnotationConfigApplicationContext​(java.lang.Class<?>... annotatedClasses)
        Create a new AnnotationConfigApplicationContext, deriving bean definitions from the given annotated classes and automatically refreshing the context.
        Parameters:
        annotatedClasses - one or more annotated classes, e.g. @Configuration classes
    • Method Detail

      • addPluginsToClasspath

        void addPluginsToClasspath()
      • addFile

        private void addFile​(java.io.File f)
      • addURL

        private void addURL​(java.net.URL u)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • invokeBeanFactoryPostProcessors

        protected void invokeBeanFactoryPostProcessors​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
        Overrides:
        invokeBeanFactoryPostProcessors in class org.springframework.context.support.AbstractApplicationContext
      • registerDependentBeanInitialisation

        protected void registerDependentBeanInitialisation​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory)
      • registerBeansFromConfiguration

        private void registerBeansFromConfiguration​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                                                    org.springframework.beans.factory.config.BeanDefinition beanDef)
      • registerBeansFromComponentScan

        private void registerBeansFromComponentScan​(org.springframework.beans.factory.config.ConfigurableListableBeanFactory beanFactory,
                                                    org.springframework.beans.factory.config.BeanDefinition beanDef)
      • getMetadataFromScannedBean

        private org.springframework.core.type.AnnotationMetadata getMetadataFromScannedBean​(org.springframework.beans.factory.config.BeanDefinition beanDef)
      • getMetadataFromConfiguration

        private org.springframework.core.type.StandardMethodMetadata getMetadataFromConfiguration​(org.springframework.beans.factory.config.BeanDefinition beanDef)
      • getBean

        public java.lang.Object getBean​(java.lang.String name)
                                 throws org.springframework.beans.BeansException
        Specified by:
        getBean in interface org.springframework.beans.factory.BeanFactory
        Overrides:
        getBean in class org.springframework.context.support.AbstractApplicationContext
        Throws:
        org.springframework.beans.BeansException
      • getBean

        public <T> T getBean​(java.lang.String name,
                             java.lang.Class<T> requiredType)
                      throws org.springframework.beans.BeansException
        Specified by:
        getBean in interface org.springframework.beans.factory.BeanFactory
        Overrides:
        getBean in class org.springframework.context.support.AbstractApplicationContext
        Throws:
        org.springframework.beans.BeansException
      • getBean

        public <T> T getBean​(java.lang.Class<T> requiredType)
                      throws org.springframework.beans.BeansException
        Specified by:
        getBean in interface org.springframework.beans.factory.BeanFactory
        Overrides:
        getBean in class org.springframework.context.support.AbstractApplicationContext
        Throws:
        org.springframework.beans.BeansException
      • getBeanNameByType

        public <T> java.lang.String getBeanNameByType​(java.lang.Class<T> requiredType)
      • getBean

        public java.lang.Object getBean​(java.lang.String name,
                                        java.lang.Object... args)
                                 throws org.springframework.beans.BeansException
        Specified by:
        getBean in interface org.springframework.beans.factory.BeanFactory
        Overrides:
        getBean in class org.springframework.context.support.AbstractApplicationContext
        Throws:
        org.springframework.beans.BeansException
      • getBean

        public <T> T getBean​(java.lang.Class<T> requiredType,
                             java.lang.Object... args)
                      throws org.springframework.beans.BeansException
        Specified by:
        getBean in interface org.springframework.beans.factory.BeanFactory
        Overrides:
        getBean in class org.springframework.context.support.AbstractApplicationContext
        Throws:
        org.springframework.beans.BeansException
      • findAllPrototypeBeans

        <T> java.util.List<T> findAllPrototypeBeans​(java.lang.Class<T> type)
      • isBeanInstantiated

        public <T> boolean isBeanInstantiated​(java.lang.Class<T> requiredType)
        Check if a bean with the matching type is instantiated.
        Type Parameters:
        T - bean type
        Parameters:
        requiredType - of the bean
        Returns:
        true if there is a bean with matching type that is instantiated.
      • isBeanInstantiated

        public boolean isBeanInstantiated​(java.lang.String beanName)
        Check if a bean with the matching name is instantiated.
        Parameters:
        beanName - name of the bean
        Returns:
        true if there is a bean with matching type that is instantiated.
      • isBeanInstantiated

        public <T> boolean isBeanInstantiated​(java.lang.Class<T> requiredType,
                                              java.lang.Object... constructorArgs)
        Check if a bean with the matching type and constructor is instantiated.
        Type Parameters:
        T - bean type
        Parameters:
        requiredType - of the bean
        constructorArgs - constructor arguments required to look up a instantiated UniquePrototype
        Returns:
        true if there is a bean with matching type that is instantiated.
      • isBeanInstantiated

        public boolean isBeanInstantiated​(java.lang.String beanName,
                                          java.lang.Object... constructorArgs)
        Check if a bean with the matching type and constructor is instantiated.
        Parameters:
        beanName - name of the bean
        constructorArgs - constructor arguments required to look up a instantiated UniquePrototype
        Returns:
        true if there is a bean with matching type that is instantiated.
      • isBeanInstantiated

        private boolean isBeanInstantiated​(java.lang.String[] beanNames,
                                           java.lang.Object... constructorArgs)
      • replaceBean

        public <T> boolean replaceBean​(T bean,
                                       T originalBean,
                                       java.util.Set<IRebinabable> rebindableObjects)
        Replace the originalBean with bean.
        Type Parameters:
        T - bean type
        Parameters:
        bean - replacing originalBean
        originalBean - instanciated bean from startup
        rebindableObjects - set of objects that are rebindable
        Returns:
        true if everything could be replaced.
      • getPrototypeBeans

        public java.util.List<java.lang.Object> getPrototypeBeans()
      • getBeans

        public java.util.List<java.lang.Object> getBeans​(java.lang.Class beanType)
        Retrieve a list of all property beans of a given type.
        Parameters:
        beanType - bean type
        Returns:
        list of beans of type beanType
      • replacePropertyBeans

        public <T> void replacePropertyBeans​(java.util.List<javafx.util.Pair<java.lang.String,​T>> newBeans)
        Remove all prototype beans of type T and put the beans in the list in instead. No autowiring happens.
        Type Parameters:
        T - type of bean
        Parameters:
        newBeans - list of pairs of bean name and bean
      • removePrototypeBean

        public <T> void removePrototypeBean​(T beanToBeRemoved)
        Remove the bean from the context.
        Type Parameters:
        T - type of bean
        Parameters:
        beanToBeRemoved - instance of the bean to be removed.