Package io.micronaut.spring.context
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
-
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
ConstructorDescriptionDefault 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, @Nullable org.springframework.context.MessageSource messageSource) Default constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
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
(String name) boolean
containsBeanDefinition
(String beanName) boolean
containsLocalBean
(String name) <A extends Annotation>
Set<A>findAllAnnotationsOnBean
(String beanName, Class<A> annotationType, boolean allowFactoryBeanInit) <A extends Annotation>
AfindAnnotationOnBean
(String beanName, Class<A> annotationType) <A extends Annotation>
AfindAnnotationOnBean
(String beanName, Class<A> annotationType, boolean allowFactoryBeanInit) String[]
getAliases
(String name) org.springframework.core.metrics.ApplicationStartup
org.springframework.beans.factory.config.AutowireCapableBeanFactory
<T> T
<T> T
<T> T
int
String[]
org.springframework.beans.factory.config.ConfigurableListableBeanFactory
String[]
getBeanNamesForAnnotation
(Class<? extends Annotation> annotationType) String[]
getBeanNamesForType
(Class<?> type) String[]
getBeanNamesForType
(Class<?> type, boolean includeNonSingletons, boolean allowEagerInit) String[]
getBeanNamesForType
(org.springframework.core.ResolvableType type) String[]
getBeanNamesForType
(org.springframework.core.ResolvableType type, boolean includeNonSingletons, boolean allowEagerInit) <T> org.springframework.beans.factory.ObjectProvider<T>
getBeanProvider
(Class<T> requiredType) <T> org.springframework.beans.factory.ObjectProvider<T>
getBeanProvider
(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) getBeansOfType
(Class<T> type) getBeansOfType
(Class<T> type, boolean includeNonSingletons, boolean allowEagerInit) getBeansWithAnnotation
(Class<? extends Annotation> annotationType) org.springframework.core.env.ConfigurableEnvironment
getId()
getMessage
(String code, Object[] args, String defaultMessage, Locale locale) getMessage
(String code, Object[] args, Locale locale) getMessage
(org.springframework.context.MessageSourceResolvable resolvable, Locale locale) org.springframework.context.ApplicationContext
org.springframework.beans.factory.BeanFactory
org.springframework.core.io.Resource
getResource
(String location) org.springframework.core.io.Resource[]
getResources
(String locationPattern) long
Class<?>
Class<?>
boolean
isActive()
boolean
isPrototype
(String name) boolean
boolean
isSingleton
(String name) boolean
isTypeMatch
(String name, Class<?> typeToMatch) boolean
isTypeMatch
(String name, org.springframework.core.ResolvableType typeToMatch) protected void
onStartup
(io.micronaut.context.event.StartupEvent startupEvent) Method executed on startup.void
publishEvent
(Object event) void
refresh()
void
void
removeApplicationListener
(org.springframework.context.ApplicationListener<?> listener) void
setApplicationStartup
(org.springframework.core.metrics.ApplicationStartup applicationStartup) void
setClassLoader
(ClassLoader classLoader) void
setEnvironment
(org.springframework.core.env.ConfigurableEnvironment environment) void
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 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 toenvironment
- The environmentbeanFactory
- The bean factoryeventPublisher
- The event publishermessageSource
- 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
- Specified by:
getId
in interfaceorg.springframework.context.ApplicationContext
-
getApplicationName
- Specified by:
getApplicationName
in interfaceorg.springframework.context.ApplicationContext
-
getDisplayName
- Specified by:
getDisplayName
in interfaceorg.springframework.context.ApplicationContext
-
getStartupDate
public long getStartupDate()- Specified by:
getStartupDate
in interfaceorg.springframework.context.ApplicationContext
-
getParent
public org.springframework.context.ApplicationContext getParent()- Specified by:
getParent
in interfaceorg.springframework.context.ApplicationContext
-
getAutowireCapableBeanFactory
public org.springframework.beans.factory.config.AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException- Specified by:
getAutowireCapableBeanFactory
in interfaceorg.springframework.context.ApplicationContext
- Throws:
IllegalStateException
-
getParentBeanFactory
public org.springframework.beans.factory.BeanFactory getParentBeanFactory()- Specified by:
getParentBeanFactory
in interfaceorg.springframework.beans.factory.HierarchicalBeanFactory
-
containsLocalBean
- Specified by:
containsLocalBean
in interfaceorg.springframework.beans.factory.HierarchicalBeanFactory
-
containsBeanDefinition
- Specified by:
containsBeanDefinition
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanDefinitionCount
public int getBeanDefinitionCount()- Specified by:
getBeanDefinitionCount
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanDefinitionNames
- Specified by:
getBeanDefinitionNames
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanProvider
public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(Class<T> requiredType, boolean allowEagerInit) - Specified by:
getBeanProvider
in interfaceorg.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 interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanNamesForType
- Specified by:
getBeanNamesForType
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanNamesForType
public String[] getBeanNamesForType(org.springframework.core.ResolvableType type, boolean includeNonSingletons, boolean allowEagerInit) - Specified by:
getBeanNamesForType
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanNamesForType
- Specified by:
getBeanNamesForType
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanNamesForType
public String[] getBeanNamesForType(Class<?> type, boolean includeNonSingletons, boolean allowEagerInit) - Specified by:
getBeanNamesForType
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeansOfType
public <T> Map<String,T> getBeansOfType(Class<T> type) throws org.springframework.beans.BeansException - Specified by:
getBeansOfType
in interfaceorg.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 interfaceorg.springframework.beans.factory.ListableBeanFactory
- Throws:
org.springframework.beans.BeansException
-
getBeanNamesForAnnotation
- Specified by:
getBeanNamesForAnnotation
in interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeansWithAnnotation
public Map<String,Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) throws org.springframework.beans.BeansException - Specified by:
getBeansWithAnnotation
in interfaceorg.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 interfaceorg.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 interfaceorg.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 interfaceorg.springframework.beans.factory.ListableBeanFactory
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
-
getBean
- Specified by:
getBean
in interfaceorg.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 interfaceorg.springframework.beans.factory.BeanFactory
- Throws:
org.springframework.beans.BeansException
-
getBean
- Specified by:
getBean
in interfaceorg.springframework.beans.factory.BeanFactory
- Throws:
org.springframework.beans.BeansException
-
getBean
- Specified by:
getBean
in interfaceorg.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 interfaceorg.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 interfaceorg.springframework.beans.factory.BeanFactory
-
getBeanProvider
public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(org.springframework.core.ResolvableType requiredType) - Specified by:
getBeanProvider
in interfaceorg.springframework.beans.factory.BeanFactory
-
containsBean
- Specified by:
containsBean
in interfaceorg.springframework.beans.factory.BeanFactory
-
isSingleton
public boolean isSingleton(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException - Specified by:
isSingleton
in interfaceorg.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 interfaceorg.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 interfaceorg.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 interfaceorg.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 interfaceorg.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 interfaceorg.springframework.beans.factory.BeanFactory
- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
-
getAliases
- Specified by:
getAliases
in interfaceorg.springframework.beans.factory.BeanFactory
-
publishEvent
- Specified by:
publishEvent
in interfaceorg.springframework.context.ApplicationEventPublisher
-
getMessage
- Specified by:
getMessage
in interfaceorg.springframework.context.MessageSource
-
getMessage
public String getMessage(String code, Object[] args, Locale locale) throws org.springframework.context.NoSuchMessageException - Specified by:
getMessage
in interfaceorg.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 interfaceorg.springframework.context.MessageSource
- Throws:
org.springframework.context.NoSuchMessageException
-
setId
- Specified by:
setId
in interfaceorg.springframework.context.ConfigurableApplicationContext
-
setParent
public void setParent(org.springframework.context.ApplicationContext parent) - Specified by:
setParent
in interfaceorg.springframework.context.ConfigurableApplicationContext
-
setEnvironment
public void setEnvironment(org.springframework.core.env.ConfigurableEnvironment environment) - Specified by:
setEnvironment
in interfaceorg.springframework.context.ConfigurableApplicationContext
-
getEnvironment
public org.springframework.core.env.ConfigurableEnvironment getEnvironment()- Specified by:
getEnvironment
in interfaceorg.springframework.context.ConfigurableApplicationContext
- Specified by:
getEnvironment
in interfaceorg.springframework.core.env.EnvironmentCapable
-
setApplicationStartup
public void setApplicationStartup(org.springframework.core.metrics.ApplicationStartup applicationStartup) - Specified by:
setApplicationStartup
in interfaceorg.springframework.context.ConfigurableApplicationContext
-
getApplicationStartup
public org.springframework.core.metrics.ApplicationStartup getApplicationStartup()- Specified by:
getApplicationStartup
in interfaceorg.springframework.context.ConfigurableApplicationContext
-
addBeanFactoryPostProcessor
public void addBeanFactoryPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor postProcessor) - Specified by:
addBeanFactoryPostProcessor
in interfaceorg.springframework.context.ConfigurableApplicationContext
-
addApplicationListener
public void addApplicationListener(org.springframework.context.ApplicationListener<?> listener) - Specified by:
addApplicationListener
in interfaceorg.springframework.context.ConfigurableApplicationContext
-
removeApplicationListener
public void removeApplicationListener(org.springframework.context.ApplicationListener<?> listener) - Specified by:
removeApplicationListener
in interfaceorg.springframework.context.ConfigurableApplicationContext
-
setClassLoader
- Specified by:
setClassLoader
in interfaceorg.springframework.context.ConfigurableApplicationContext
-
addProtocolResolver
public void addProtocolResolver(org.springframework.core.io.ProtocolResolver resolver) - Specified by:
addProtocolResolver
in interfaceorg.springframework.context.ConfigurableApplicationContext
-
refresh
- Specified by:
refresh
in interfaceorg.springframework.context.ConfigurableApplicationContext
- Throws:
org.springframework.beans.BeansException
IllegalStateException
-
registerShutdownHook
public void registerShutdownHook()- Specified by:
registerShutdownHook
in interfaceorg.springframework.context.ConfigurableApplicationContext
-
getResources
public org.springframework.core.io.Resource[] getResources(String locationPattern) throws IOException - Specified by:
getResources
in interfaceorg.springframework.core.io.support.ResourcePatternResolver
- Throws:
IOException
-
getResource
- Specified by:
getResource
in interfaceorg.springframework.core.io.ResourceLoader
-
getClassLoader
- Specified by:
getClassLoader
in interfaceorg.springframework.core.io.ResourceLoader
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in interfaceorg.springframework.context.ConfigurableApplicationContext
-
isActive
public boolean isActive()- Specified by:
isActive
in interfaceorg.springframework.context.ConfigurableApplicationContext
-
getBeanFactory
public org.springframework.beans.factory.config.ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException- Specified by:
getBeanFactory
in interfaceorg.springframework.context.ConfigurableApplicationContext
- Throws:
IllegalStateException
-
start
public void start()- Specified by:
start
in interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stop
in interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunning
in interfaceorg.springframework.context.Lifecycle
-
onStartup
@EventListener protected void onStartup(io.micronaut.context.event.StartupEvent startupEvent) Method executed on startup.- Parameters:
startupEvent
- The startup event.
-