Class MicronautApplicationContext

java.lang.Object
io.micronaut.spring.context.MicronautApplicationContext
All Implemented Interfaces:
MicronautContextInternal, ManagedApplicationContext, Closeable, 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 Object implements ManagedApplicationContext, org.springframework.context.ConfigurableApplicationContext, 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
Author:
graemerocher
  • Constructor Details

    • MicronautApplicationContext

      @Inject public MicronautApplicationContext(io.micronaut.context.ApplicationContext micronautContext, org.springframework.core.env.ConfigurableEnvironment environment, MicronautBeanFactory beanFactory, org.springframework.context.ApplicationEventPublisher eventPublisher, @Nullable @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 Details

    • getId

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

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

      public 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 IllegalStateException
      Specified by:
      getAutowireCapableBeanFactory in interface org.springframework.context.ApplicationContext
      Throws:
      IllegalStateException
    • getParentBeanFactory

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

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

      public boolean containsBeanDefinition(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 String[] getBeanDefinitionNames()
      Specified by:
      getBeanDefinitionNames in interface org.springframework.beans.factory.ListableBeanFactory
    • getBeanProvider

      public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(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 String[] getBeanNamesForType(org.springframework.core.ResolvableType type)
      Specified by:
      getBeanNamesForType in interface org.springframework.beans.factory.ListableBeanFactory
    • getBeanNamesForType

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

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

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

      public <T> Map<String,T> getBeansOfType(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> Map<String,T> getBeansOfType(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 String[] getBeanNamesForAnnotation(Class<? extends Annotation> annotationType)
      Specified by:
      getBeanNamesForAnnotation in interface org.springframework.beans.factory.ListableBeanFactory
    • getBeansWithAnnotation

      public Map<String,Object> getBeansWithAnnotation(Class<? extends 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 Annotation> A findAnnotationOnBean(String beanName, 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 Annotation> A findAnnotationOnBean(String beanName, 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
    • findAllAnnotationsOnBean

      public <A extends Annotation> Set<A> findAllAnnotationsOnBean(String beanName, Class<A> annotationType, boolean allowFactoryBeanInit) throws org.springframework.beans.factory.NoSuchBeanDefinitionException
      Specified by:
      findAllAnnotationsOnBean in interface org.springframework.beans.factory.ListableBeanFactory
      Throws:
      org.springframework.beans.factory.NoSuchBeanDefinitionException
    • getBean

      public Object getBean(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(String name, 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 Object getBean(String name, 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(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(Class<T> requiredType, 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(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(String name)
      Specified by:
      containsBean in interface org.springframework.beans.factory.BeanFactory
    • isSingleton

      public boolean isSingleton(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(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(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(String name, 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 Class<?> getType(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 Class<?> getType(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 String[] getAliases(String name)
      Specified by:
      getAliases in interface org.springframework.beans.factory.BeanFactory
    • publishEvent

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

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

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

      public String getMessage(org.springframework.context.MessageSourceResolvable resolvable, 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(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
    • removeApplicationListener

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

      public void setClassLoader(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, IllegalStateException
      Specified by:
      refresh in interface org.springframework.context.ConfigurableApplicationContext
      Throws:
      org.springframework.beans.BeansException
      IllegalStateException
    • registerShutdownHook

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

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

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

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

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Specified by:
      close in interface org.springframework.context.ConfigurableApplicationContext
    • isClosed

      public boolean isClosed()
      Specified by:
      isClosed 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 IllegalStateException
      Specified by:
      getBeanFactory in interface org.springframework.context.ConfigurableApplicationContext
      Throws:
      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.