Class MicronautApplicationContext

  • All Implemented Interfaces:
    io.micronaut.spring.beans.MicronautContextInternal, ManagedApplicationContext, java.io.Closeable, java.lang.AutoCloseable, org.springframework.beans.factory.BeanFactory, org.springframework.beans.factory.HierarchicalBeanFactory, org.springframework.beans.factory.ListableBeanFactory, org.springframework.context.ApplicationContext, org.springframework.context.ApplicationEventPublisher, org.springframework.context.ConfigurableApplicationContext, org.springframework.context.Lifecycle, org.springframework.context.MessageSource, org.springframework.core.env.EnvironmentCapable, org.springframework.core.io.ResourceLoader, org.springframework.core.io.support.ResourcePatternResolver

    @Singleton
    @Secondary
    public class MicronautApplicationContext
    extends java.lang.Object
    implements ManagedApplicationContext, org.springframework.context.ConfigurableApplicationContext, io.micronaut.spring.beans.MicronautContextInternal
    An implementation of Spring's ApplicationContext interface that delegates to Micronaut.

    This can either be created manually via MicronautApplicationContext(ApplicationContextBuilder) or looked up as a bean when running from Micronaut. The ApplicationContextAware interface is supported.

    Since:
    1.0
    • Field Summary

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

        FACTORY_BEAN_PREFIX
      • Fields inherited from interface org.springframework.context.ConfigurableApplicationContext

        APPLICATION_STARTUP_BEAN_NAME, CONFIG_LOCATION_DELIMITERS, CONVERSION_SERVICE_BEAN_NAME, ENVIRONMENT_BEAN_NAME, LOAD_TIME_WEAVER_BEAN_NAME, SHUTDOWN_HOOK_THREAD_NAME, SYSTEM_ENVIRONMENT_BEAN_NAME, SYSTEM_PROPERTIES_BEAN_NAME
      • Fields inherited from interface org.springframework.core.io.ResourceLoader

        CLASSPATH_URL_PREFIX
      • Fields inherited from interface org.springframework.core.io.support.ResourcePatternResolver

        CLASSPATH_ALL_URL_PREFIX
    • Constructor Summary

      Constructors 
      Constructor Description
      MicronautApplicationContext()
      Default constructor.
      MicronautApplicationContext​(io.micronaut.context.ApplicationContextBuilder contextBuilder)
      Customization constructor.
      MicronautApplicationContext​(io.micronaut.context.ApplicationContext micronautContext, org.springframework.core.env.ConfigurableEnvironment environment, MicronautBeanFactory beanFactory, org.springframework.context.ApplicationEventPublisher eventPublisher, org.springframework.context.MessageSource messageSource)
      Default constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addApplicationListener​(org.springframework.context.ApplicationListener<?> listener)  
      void addBeanFactoryPostProcessor​(org.springframework.beans.factory.config.BeanFactoryPostProcessor postProcessor)  
      void addProtocolResolver​(org.springframework.core.io.ProtocolResolver resolver)  
      void close()  
      boolean containsBean​(java.lang.String name)  
      boolean containsBeanDefinition​(java.lang.String beanName)  
      boolean containsLocalBean​(java.lang.String name)  
      <A extends java.lang.annotation.Annotation>
      A
      findAnnotationOnBean​(java.lang.String beanName, java.lang.Class<A> annotationType)  
      <A extends java.lang.annotation.Annotation>
      A
      findAnnotationOnBean​(java.lang.String beanName, java.lang.Class<A> annotationType, boolean allowFactoryBeanInit)  
      java.lang.String[] getAliases​(java.lang.String name)  
      java.lang.String getApplicationName()  
      org.springframework.core.metrics.ApplicationStartup getApplicationStartup()  
      org.springframework.beans.factory.config.AutowireCapableBeanFactory getAutowireCapableBeanFactory()  
      <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)  
      int getBeanDefinitionCount()  
      java.lang.String[] getBeanDefinitionNames()  
      org.springframework.beans.factory.config.ConfigurableListableBeanFactory getBeanFactory()  
      java.lang.String[] getBeanNamesForAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)  
      java.lang.String[] getBeanNamesForType​(java.lang.Class<?> type)  
      java.lang.String[] getBeanNamesForType​(java.lang.Class<?> type, boolean includeNonSingletons, boolean allowEagerInit)  
      java.lang.String[] getBeanNamesForType​(org.springframework.core.ResolvableType type)  
      java.lang.String[] getBeanNamesForType​(org.springframework.core.ResolvableType type, boolean includeNonSingletons, boolean allowEagerInit)  
      <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider​(java.lang.Class<T> requiredType)  
      <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider​(java.lang.Class<T> requiredType, boolean allowEagerInit)  
      <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider​(org.springframework.core.ResolvableType requiredType)  
      <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider​(org.springframework.core.ResolvableType requiredType, boolean allowEagerInit)  
      <T> java.util.Map<java.lang.String,​T> getBeansOfType​(java.lang.Class<T> type)  
      <T> java.util.Map<java.lang.String,​T> getBeansOfType​(java.lang.Class<T> type, boolean includeNonSingletons, boolean allowEagerInit)  
      java.util.Map<java.lang.String,​java.lang.Object> getBeansWithAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)  
      java.lang.ClassLoader getClassLoader()  
      java.lang.String getDisplayName()  
      org.springframework.core.env.ConfigurableEnvironment getEnvironment()  
      java.lang.String getId()  
      java.lang.String getMessage​(java.lang.String code, java.lang.Object[] args, java.lang.String defaultMessage, java.util.Locale locale)  
      java.lang.String getMessage​(java.lang.String code, java.lang.Object[] args, java.util.Locale locale)  
      java.lang.String getMessage​(org.springframework.context.MessageSourceResolvable resolvable, java.util.Locale locale)  
      org.springframework.context.ApplicationContext getParent()  
      org.springframework.beans.factory.BeanFactory getParentBeanFactory()  
      org.springframework.core.io.Resource getResource​(java.lang.String location)  
      org.springframework.core.io.Resource[] getResources​(java.lang.String locationPattern)  
      long getStartupDate()  
      java.lang.Class<?> getType​(java.lang.String name)  
      java.lang.Class<?> getType​(java.lang.String name, boolean allowFactoryBeanInit)  
      boolean isActive()  
      boolean isPrototype​(java.lang.String name)  
      boolean isRunning()  
      boolean isSingleton​(java.lang.String name)  
      boolean isTypeMatch​(java.lang.String name, java.lang.Class<?> typeToMatch)  
      boolean isTypeMatch​(java.lang.String name, org.springframework.core.ResolvableType typeToMatch)  
      protected void onStartup​(io.micronaut.context.event.StartupEvent startupEvent)
      Method executed on startup.
      void publishEvent​(java.lang.Object event)  
      void refresh()  
      void registerShutdownHook()  
      void setApplicationStartup​(org.springframework.core.metrics.ApplicationStartup applicationStartup)  
      void setClassLoader​(java.lang.ClassLoader classLoader)  
      void setEnvironment​(org.springframework.core.env.ConfigurableEnvironment environment)  
      void setId​(java.lang.String id)  
      void setParent​(org.springframework.context.ApplicationContext parent)  
      void start()  
      void stop()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface org.springframework.context.ApplicationEventPublisher

        publishEvent
    • Constructor Detail

      • MicronautApplicationContext

        @Inject
        public MicronautApplicationContext​(io.micronaut.context.ApplicationContext micronautContext,
                                           org.springframework.core.env.ConfigurableEnvironment environment,
                                           MicronautBeanFactory beanFactory,
                                           org.springframework.context.ApplicationEventPublisher eventPublisher,
                                           @Nullable
                                           org.springframework.context.MessageSource messageSource)
        Default constructor.
        Parameters:
        micronautContext - The micronaut context to delegate to
        environment - The environment
        beanFactory - The bean factory
        eventPublisher - The event publisher
        messageSource - The message source
      • MicronautApplicationContext

        public MicronautApplicationContext()
        Default constructor.
      • MicronautApplicationContext

        public MicronautApplicationContext​(io.micronaut.context.ApplicationContextBuilder contextBuilder)
        Customization constructor.
        Parameters:
        contextBuilder - The context builder
    • Method Detail

      • getId

        public java.lang.String getId()
        Specified by:
        getId in interface org.springframework.context.ApplicationContext
      • getApplicationName

        public java.lang.String getApplicationName()
        Specified by:
        getApplicationName in interface org.springframework.context.ApplicationContext
      • getDisplayName

        public java.lang.String getDisplayName()
        Specified by:
        getDisplayName in interface org.springframework.context.ApplicationContext
      • getStartupDate

        public long getStartupDate()
        Specified by:
        getStartupDate in interface org.springframework.context.ApplicationContext
      • getParent

        public org.springframework.context.ApplicationContext getParent()
        Specified by:
        getParent in interface org.springframework.context.ApplicationContext
      • getAutowireCapableBeanFactory

        public org.springframework.beans.factory.config.AutowireCapableBeanFactory getAutowireCapableBeanFactory()
                                                                                                          throws java.lang.IllegalStateException
        Specified by:
        getAutowireCapableBeanFactory in interface org.springframework.context.ApplicationContext
        Throws:
        java.lang.IllegalStateException
      • getParentBeanFactory

        public org.springframework.beans.factory.BeanFactory getParentBeanFactory()
        Specified by:
        getParentBeanFactory in interface org.springframework.beans.factory.HierarchicalBeanFactory
      • containsLocalBean

        public boolean containsLocalBean​(java.lang.String name)
        Specified by:
        containsLocalBean in interface org.springframework.beans.factory.HierarchicalBeanFactory
      • containsBeanDefinition

        public boolean containsBeanDefinition​(java.lang.String beanName)
        Specified by:
        containsBeanDefinition in interface org.springframework.beans.factory.ListableBeanFactory
      • getBeanDefinitionCount

        public int getBeanDefinitionCount()
        Specified by:
        getBeanDefinitionCount in interface org.springframework.beans.factory.ListableBeanFactory
      • getBeanDefinitionNames

        public java.lang.String[] getBeanDefinitionNames()
        Specified by:
        getBeanDefinitionNames in interface org.springframework.beans.factory.ListableBeanFactory
      • getBeanProvider

        public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider​(java.lang.Class<T> requiredType,
                                                                                       boolean allowEagerInit)
        Specified by:
        getBeanProvider in interface org.springframework.beans.factory.ListableBeanFactory
      • getBeanProvider

        public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider​(org.springframework.core.ResolvableType requiredType,
                                                                                       boolean allowEagerInit)
        Specified by:
        getBeanProvider in interface org.springframework.beans.factory.ListableBeanFactory
      • getBeanNamesForType

        public java.lang.String[] getBeanNamesForType​(org.springframework.core.ResolvableType type)
        Specified by:
        getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactory
      • getBeanNamesForType

        public java.lang.String[] getBeanNamesForType​(org.springframework.core.ResolvableType type,
                                                      boolean includeNonSingletons,
                                                      boolean allowEagerInit)
        Specified by:
        getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactory
      • getBeanNamesForType

        public java.lang.String[] getBeanNamesForType​(java.lang.Class<?> type)
        Specified by:
        getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactory
      • getBeanNamesForType

        public java.lang.String[] getBeanNamesForType​(java.lang.Class<?> type,
                                                      boolean includeNonSingletons,
                                                      boolean allowEagerInit)
        Specified by:
        getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactory
      • getBeansOfType

        public <T> java.util.Map<java.lang.String,​T> getBeansOfType​(java.lang.Class<T> type)
                                                                   throws org.springframework.beans.BeansException
        Specified by:
        getBeansOfType in interface org.springframework.beans.factory.ListableBeanFactory
        Throws:
        org.springframework.beans.BeansException
      • getBeansOfType

        public <T> java.util.Map<java.lang.String,​T> getBeansOfType​(java.lang.Class<T> type,
                                                                          boolean includeNonSingletons,
                                                                          boolean allowEagerInit)
                                                                   throws org.springframework.beans.BeansException
        Specified by:
        getBeansOfType in interface org.springframework.beans.factory.ListableBeanFactory
        Throws:
        org.springframework.beans.BeansException
      • getBeanNamesForAnnotation

        public java.lang.String[] getBeanNamesForAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
        Specified by:
        getBeanNamesForAnnotation in interface org.springframework.beans.factory.ListableBeanFactory
      • getBeansWithAnnotation

        public java.util.Map<java.lang.String,​java.lang.Object> getBeansWithAnnotation​(java.lang.Class<? extends java.lang.annotation.Annotation> annotationType)
                                                                                      throws org.springframework.beans.BeansException
        Specified by:
        getBeansWithAnnotation in interface org.springframework.beans.factory.ListableBeanFactory
        Throws:
        org.springframework.beans.BeansException
      • findAnnotationOnBean

        public <A extends java.lang.annotation.Annotation> A findAnnotationOnBean​(java.lang.String beanName,
                                                                                  java.lang.Class<A> annotationType)
                                                                           throws org.springframework.beans.factory.NoSuchBeanDefinitionException
        Specified by:
        findAnnotationOnBean in interface org.springframework.beans.factory.ListableBeanFactory
        Throws:
        org.springframework.beans.factory.NoSuchBeanDefinitionException
      • findAnnotationOnBean

        public <A extends java.lang.annotation.Annotation> A findAnnotationOnBean​(java.lang.String beanName,
                                                                                  java.lang.Class<A> annotationType,
                                                                                  boolean allowFactoryBeanInit)
                                                                           throws org.springframework.beans.factory.NoSuchBeanDefinitionException
        Specified by:
        findAnnotationOnBean in interface org.springframework.beans.factory.ListableBeanFactory
        Throws:
        org.springframework.beans.factory.NoSuchBeanDefinitionException
      • 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
        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
        Throws:
        org.springframework.beans.BeansException
      • 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
        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
        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
        Throws:
        org.springframework.beans.BeansException
      • getBeanProvider

        public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider​(java.lang.Class<T> requiredType)
        Specified by:
        getBeanProvider in interface org.springframework.beans.factory.BeanFactory
      • getBeanProvider

        public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider​(org.springframework.core.ResolvableType requiredType)
        Specified by:
        getBeanProvider in interface org.springframework.beans.factory.BeanFactory
      • containsBean

        public boolean containsBean​(java.lang.String name)
        Specified by:
        containsBean in interface org.springframework.beans.factory.BeanFactory
      • isSingleton

        public boolean isSingleton​(java.lang.String name)
                            throws org.springframework.beans.factory.NoSuchBeanDefinitionException
        Specified by:
        isSingleton in interface org.springframework.beans.factory.BeanFactory
        Throws:
        org.springframework.beans.factory.NoSuchBeanDefinitionException
      • isPrototype

        public boolean isPrototype​(java.lang.String name)
                            throws org.springframework.beans.factory.NoSuchBeanDefinitionException
        Specified by:
        isPrototype in interface org.springframework.beans.factory.BeanFactory
        Throws:
        org.springframework.beans.factory.NoSuchBeanDefinitionException
      • isTypeMatch

        public boolean isTypeMatch​(java.lang.String name,
                                   org.springframework.core.ResolvableType typeToMatch)
                            throws org.springframework.beans.factory.NoSuchBeanDefinitionException
        Specified by:
        isTypeMatch in interface org.springframework.beans.factory.BeanFactory
        Throws:
        org.springframework.beans.factory.NoSuchBeanDefinitionException
      • isTypeMatch

        public boolean isTypeMatch​(java.lang.String name,
                                   java.lang.Class<?> typeToMatch)
                            throws org.springframework.beans.factory.NoSuchBeanDefinitionException
        Specified by:
        isTypeMatch in interface org.springframework.beans.factory.BeanFactory
        Throws:
        org.springframework.beans.factory.NoSuchBeanDefinitionException
      • getType

        public java.lang.Class<?> getType​(java.lang.String name)
                                   throws org.springframework.beans.factory.NoSuchBeanDefinitionException
        Specified by:
        getType in interface org.springframework.beans.factory.BeanFactory
        Throws:
        org.springframework.beans.factory.NoSuchBeanDefinitionException
      • getType

        public java.lang.Class<?> getType​(java.lang.String name,
                                          boolean allowFactoryBeanInit)
                                   throws org.springframework.beans.factory.NoSuchBeanDefinitionException
        Specified by:
        getType in interface org.springframework.beans.factory.BeanFactory
        Throws:
        org.springframework.beans.factory.NoSuchBeanDefinitionException
      • getAliases

        public java.lang.String[] getAliases​(java.lang.String name)
        Specified by:
        getAliases in interface org.springframework.beans.factory.BeanFactory
      • publishEvent

        public void publishEvent​(java.lang.Object event)
        Specified by:
        publishEvent in interface org.springframework.context.ApplicationEventPublisher
      • getMessage

        public java.lang.String getMessage​(java.lang.String code,
                                           java.lang.Object[] args,
                                           java.lang.String defaultMessage,
                                           java.util.Locale locale)
        Specified by:
        getMessage in interface org.springframework.context.MessageSource
      • getMessage

        public java.lang.String getMessage​(java.lang.String code,
                                           java.lang.Object[] args,
                                           java.util.Locale locale)
                                    throws org.springframework.context.NoSuchMessageException
        Specified by:
        getMessage in interface org.springframework.context.MessageSource
        Throws:
        org.springframework.context.NoSuchMessageException
      • getMessage

        public java.lang.String getMessage​(org.springframework.context.MessageSourceResolvable resolvable,
                                           java.util.Locale locale)
                                    throws org.springframework.context.NoSuchMessageException
        Specified by:
        getMessage in interface org.springframework.context.MessageSource
        Throws:
        org.springframework.context.NoSuchMessageException
      • setId

        public void setId​(java.lang.String id)
        Specified by:
        setId in interface org.springframework.context.ConfigurableApplicationContext
      • setParent

        public void setParent​(org.springframework.context.ApplicationContext parent)
        Specified by:
        setParent in interface org.springframework.context.ConfigurableApplicationContext
      • setEnvironment

        public void setEnvironment​(org.springframework.core.env.ConfigurableEnvironment environment)
        Specified by:
        setEnvironment in interface org.springframework.context.ConfigurableApplicationContext
      • getEnvironment

        public org.springframework.core.env.ConfigurableEnvironment getEnvironment()
        Specified by:
        getEnvironment in interface org.springframework.context.ConfigurableApplicationContext
        Specified by:
        getEnvironment in interface org.springframework.core.env.EnvironmentCapable
      • setApplicationStartup

        public void setApplicationStartup​(org.springframework.core.metrics.ApplicationStartup applicationStartup)
        Specified by:
        setApplicationStartup in interface org.springframework.context.ConfigurableApplicationContext
      • getApplicationStartup

        public org.springframework.core.metrics.ApplicationStartup getApplicationStartup()
        Specified by:
        getApplicationStartup in interface org.springframework.context.ConfigurableApplicationContext
      • addBeanFactoryPostProcessor

        public void addBeanFactoryPostProcessor​(org.springframework.beans.factory.config.BeanFactoryPostProcessor postProcessor)
        Specified by:
        addBeanFactoryPostProcessor in interface org.springframework.context.ConfigurableApplicationContext
      • addApplicationListener

        public void addApplicationListener​(org.springframework.context.ApplicationListener<?> listener)
        Specified by:
        addApplicationListener in interface org.springframework.context.ConfigurableApplicationContext
      • setClassLoader

        public void setClassLoader​(java.lang.ClassLoader classLoader)
        Specified by:
        setClassLoader in interface org.springframework.context.ConfigurableApplicationContext
      • addProtocolResolver

        public void addProtocolResolver​(org.springframework.core.io.ProtocolResolver resolver)
        Specified by:
        addProtocolResolver in interface org.springframework.context.ConfigurableApplicationContext
      • refresh

        public void refresh()
                     throws org.springframework.beans.BeansException,
                            java.lang.IllegalStateException
        Specified by:
        refresh in interface org.springframework.context.ConfigurableApplicationContext
        Throws:
        org.springframework.beans.BeansException
        java.lang.IllegalStateException
      • registerShutdownHook

        public void registerShutdownHook()
        Specified by:
        registerShutdownHook in interface org.springframework.context.ConfigurableApplicationContext
      • getResources

        public org.springframework.core.io.Resource[] getResources​(java.lang.String locationPattern)
                                                            throws java.io.IOException
        Specified by:
        getResources in interface org.springframework.core.io.support.ResourcePatternResolver
        Throws:
        java.io.IOException
      • getResource

        public org.springframework.core.io.Resource getResource​(java.lang.String location)
        Specified by:
        getResource in interface org.springframework.core.io.ResourceLoader
      • getClassLoader

        public java.lang.ClassLoader getClassLoader()
        Specified by:
        getClassLoader in interface org.springframework.core.io.ResourceLoader
      • close

        public void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Specified by:
        close in interface org.springframework.context.ConfigurableApplicationContext
      • isActive

        public boolean isActive()
        Specified by:
        isActive in interface org.springframework.context.ConfigurableApplicationContext
      • getBeanFactory

        public org.springframework.beans.factory.config.ConfigurableListableBeanFactory getBeanFactory()
                                                                                                throws java.lang.IllegalStateException
        Specified by:
        getBeanFactory in interface org.springframework.context.ConfigurableApplicationContext
        Throws:
        java.lang.IllegalStateException
      • start

        public void start()
        Specified by:
        start in interface org.springframework.context.Lifecycle
      • stop

        public void stop()
        Specified by:
        stop in interface org.springframework.context.Lifecycle
      • isRunning

        public boolean isRunning()
        Specified by:
        isRunning in interface org.springframework.context.Lifecycle
      • onStartup

        @EventListener
        protected void onStartup​(io.micronaut.context.event.StartupEvent startupEvent)
        Method executed on startup.
        Parameters:
        startupEvent - The startup event.