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, FACTORY_BEAN_PREFIX_CHARFields inherited from interface org.springframework.context.ConfigurableApplicationContext
APPLICATION_STARTUP_BEAN_NAME, BOOTSTRAP_EXECUTOR_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_NAMEFields inherited from interface org.springframework.core.io.ResourceLoader
CLASSPATH_URL_PREFIXFields inherited from interface org.springframework.core.io.support.ResourcePatternResolver
CLASSPATH_ALL_URL_PREFIX -
Constructor Summary
ConstructorsConstructorDescriptionDefault 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 TypeMethodDescriptionvoidaddApplicationListener(org.springframework.context.ApplicationListener<?> listener) voidaddBeanFactoryPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor postProcessor) voidaddProtocolResolver(org.springframework.core.io.ProtocolResolver resolver) voidclose()booleancontainsBean(String name) booleancontainsBeanDefinition(String beanName) booleancontainsLocalBean(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.ApplicationStartuporg.springframework.beans.factory.config.AutowireCapableBeanFactory<T> T<T> T<T> TintString[]org.springframework.beans.factory.config.ConfigurableListableBeanFactoryString[]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.ConfigurableEnvironmentgetId()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.ApplicationContextorg.springframework.beans.factory.BeanFactoryorg.springframework.core.io.ResourcegetResource(String location) org.springframework.core.io.Resource[]getResources(String locationPattern) longClass<?>Class<?>booleanisActive()booleanisClosed()booleanisPrototype(String name) booleanbooleanisSingleton(String name) booleanisTypeMatch(String name, Class<?> typeToMatch) booleanisTypeMatch(String name, org.springframework.core.ResolvableType typeToMatch) protected voidonStartup(io.micronaut.context.event.StartupEvent startupEvent) Method executed on startup.voidpublishEvent(Object event) voidrefresh()voidvoidremoveApplicationListener(org.springframework.context.ApplicationListener<?> listener) voidsetApplicationStartup(org.springframework.core.metrics.ApplicationStartup applicationStartup) voidsetClassLoader(ClassLoader classLoader) voidsetEnvironment(org.springframework.core.env.ConfigurableEnvironment environment) voidvoidsetParent(org.springframework.context.ApplicationContext parent) voidstart()voidstop()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods 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:
getIdin interfaceorg.springframework.context.ApplicationContext
-
getApplicationName
- Specified by:
getApplicationNamein interfaceorg.springframework.context.ApplicationContext
-
getDisplayName
- Specified by:
getDisplayNamein interfaceorg.springframework.context.ApplicationContext
-
getStartupDate
public long getStartupDate()- Specified by:
getStartupDatein interfaceorg.springframework.context.ApplicationContext
-
getParent
public org.springframework.context.ApplicationContext getParent()- Specified by:
getParentin interfaceorg.springframework.context.ApplicationContext
-
getAutowireCapableBeanFactory
public org.springframework.beans.factory.config.AutowireCapableBeanFactory getAutowireCapableBeanFactory() throws IllegalStateException- Specified by:
getAutowireCapableBeanFactoryin interfaceorg.springframework.context.ApplicationContext- Throws:
IllegalStateException
-
getParentBeanFactory
public org.springframework.beans.factory.BeanFactory getParentBeanFactory()- Specified by:
getParentBeanFactoryin interfaceorg.springframework.beans.factory.HierarchicalBeanFactory
-
containsLocalBean
- Specified by:
containsLocalBeanin interfaceorg.springframework.beans.factory.HierarchicalBeanFactory
-
containsBeanDefinition
- Specified by:
containsBeanDefinitionin interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanDefinitionCount
public int getBeanDefinitionCount()- Specified by:
getBeanDefinitionCountin interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanDefinitionNames
- Specified by:
getBeanDefinitionNamesin interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanProvider
public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(Class<T> requiredType, boolean allowEagerInit) - Specified by:
getBeanProviderin interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanProvider
public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(org.springframework.core.ResolvableType requiredType, boolean allowEagerInit) - Specified by:
getBeanProviderin interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanNamesForType
- Specified by:
getBeanNamesForTypein interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanNamesForType
public String[] getBeanNamesForType(org.springframework.core.ResolvableType type, boolean includeNonSingletons, boolean allowEagerInit) - Specified by:
getBeanNamesForTypein interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanNamesForType
- Specified by:
getBeanNamesForTypein interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeanNamesForType
public String[] getBeanNamesForType(Class<?> type, boolean includeNonSingletons, boolean allowEagerInit) - Specified by:
getBeanNamesForTypein interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeansOfType
public <T> Map<String,T> getBeansOfType(Class<T> type) throws org.springframework.beans.BeansException - Specified by:
getBeansOfTypein 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:
getBeansOfTypein interfaceorg.springframework.beans.factory.ListableBeanFactory- Throws:
org.springframework.beans.BeansException
-
getBeanNamesForAnnotation
- Specified by:
getBeanNamesForAnnotationin interfaceorg.springframework.beans.factory.ListableBeanFactory
-
getBeansWithAnnotation
public Map<String,Object> getBeansWithAnnotation(Class<? extends Annotation> annotationType) throws org.springframework.beans.BeansException - Specified by:
getBeansWithAnnotationin 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:
findAnnotationOnBeanin 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:
findAnnotationOnBeanin 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:
findAllAnnotationsOnBeanin interfaceorg.springframework.beans.factory.ListableBeanFactory- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
-
getBean
- Specified by:
getBeanin 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:
getBeanin interfaceorg.springframework.beans.factory.BeanFactory- Throws:
org.springframework.beans.BeansException
-
getBean
- Specified by:
getBeanin interfaceorg.springframework.beans.factory.BeanFactory- Throws:
org.springframework.beans.BeansException
-
getBean
- Specified by:
getBeanin 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:
getBeanin 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:
getBeanProviderin interfaceorg.springframework.beans.factory.BeanFactory
-
getBeanProvider
public <T> org.springframework.beans.factory.ObjectProvider<T> getBeanProvider(org.springframework.core.ResolvableType requiredType) - Specified by:
getBeanProviderin interfaceorg.springframework.beans.factory.BeanFactory
-
containsBean
- Specified by:
containsBeanin interfaceorg.springframework.beans.factory.BeanFactory
-
isSingleton
public boolean isSingleton(String name) throws org.springframework.beans.factory.NoSuchBeanDefinitionException - Specified by:
isSingletonin 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:
isPrototypein 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:
isTypeMatchin 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:
isTypeMatchin 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:
getTypein 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:
getTypein interfaceorg.springframework.beans.factory.BeanFactory- Throws:
org.springframework.beans.factory.NoSuchBeanDefinitionException
-
getAliases
- Specified by:
getAliasesin interfaceorg.springframework.beans.factory.BeanFactory
-
publishEvent
- Specified by:
publishEventin interfaceorg.springframework.context.ApplicationEventPublisher
-
getMessage
- Specified by:
getMessagein interfaceorg.springframework.context.MessageSource
-
getMessage
public String getMessage(String code, Object[] args, Locale locale) throws org.springframework.context.NoSuchMessageException - Specified by:
getMessagein 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:
getMessagein interfaceorg.springframework.context.MessageSource- Throws:
org.springframework.context.NoSuchMessageException
-
setId
- Specified by:
setIdin interfaceorg.springframework.context.ConfigurableApplicationContext
-
setParent
public void setParent(org.springframework.context.ApplicationContext parent) - Specified by:
setParentin interfaceorg.springframework.context.ConfigurableApplicationContext
-
setEnvironment
public void setEnvironment(org.springframework.core.env.ConfigurableEnvironment environment) - Specified by:
setEnvironmentin interfaceorg.springframework.context.ConfigurableApplicationContext
-
getEnvironment
public org.springframework.core.env.ConfigurableEnvironment getEnvironment()- Specified by:
getEnvironmentin interfaceorg.springframework.context.ConfigurableApplicationContext- Specified by:
getEnvironmentin interfaceorg.springframework.core.env.EnvironmentCapable
-
setApplicationStartup
public void setApplicationStartup(org.springframework.core.metrics.ApplicationStartup applicationStartup) - Specified by:
setApplicationStartupin interfaceorg.springframework.context.ConfigurableApplicationContext
-
getApplicationStartup
public org.springframework.core.metrics.ApplicationStartup getApplicationStartup()- Specified by:
getApplicationStartupin interfaceorg.springframework.context.ConfigurableApplicationContext
-
addBeanFactoryPostProcessor
public void addBeanFactoryPostProcessor(org.springframework.beans.factory.config.BeanFactoryPostProcessor postProcessor) - Specified by:
addBeanFactoryPostProcessorin interfaceorg.springframework.context.ConfigurableApplicationContext
-
addApplicationListener
public void addApplicationListener(org.springframework.context.ApplicationListener<?> listener) - Specified by:
addApplicationListenerin interfaceorg.springframework.context.ConfigurableApplicationContext
-
removeApplicationListener
public void removeApplicationListener(org.springframework.context.ApplicationListener<?> listener) - Specified by:
removeApplicationListenerin interfaceorg.springframework.context.ConfigurableApplicationContext
-
setClassLoader
- Specified by:
setClassLoaderin interfaceorg.springframework.context.ConfigurableApplicationContext
-
addProtocolResolver
public void addProtocolResolver(org.springframework.core.io.ProtocolResolver resolver) - Specified by:
addProtocolResolverin interfaceorg.springframework.context.ConfigurableApplicationContext
-
refresh
- Specified by:
refreshin interfaceorg.springframework.context.ConfigurableApplicationContext- Throws:
org.springframework.beans.BeansExceptionIllegalStateException
-
registerShutdownHook
public void registerShutdownHook()- Specified by:
registerShutdownHookin interfaceorg.springframework.context.ConfigurableApplicationContext
-
getResources
public org.springframework.core.io.Resource[] getResources(String locationPattern) throws IOException - Specified by:
getResourcesin interfaceorg.springframework.core.io.support.ResourcePatternResolver- Throws:
IOException
-
getResource
- Specified by:
getResourcein interfaceorg.springframework.core.io.ResourceLoader
-
getClassLoader
- Specified by:
getClassLoaderin interfaceorg.springframework.core.io.ResourceLoader
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Specified by:
closein interfaceorg.springframework.context.ConfigurableApplicationContext
-
isClosed
public boolean isClosed()- Specified by:
isClosedin interfaceorg.springframework.context.ConfigurableApplicationContext
-
isActive
public boolean isActive()- Specified by:
isActivein interfaceorg.springframework.context.ConfigurableApplicationContext
-
getBeanFactory
public org.springframework.beans.factory.config.ConfigurableListableBeanFactory getBeanFactory() throws IllegalStateException- Specified by:
getBeanFactoryin interfaceorg.springframework.context.ConfigurableApplicationContext- Throws:
IllegalStateException
-
start
public void start()- Specified by:
startin interfaceorg.springframework.context.Lifecycle
-
stop
public void stop()- Specified by:
stopin interfaceorg.springframework.context.Lifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceorg.springframework.context.Lifecycle
-
onStartup
@EventListener protected void onStartup(io.micronaut.context.event.StartupEvent startupEvent) Method executed on startup.- Parameters:
startupEvent- The startup event.
-