public interface ApplicationContext extends BeanContext, PropertyResolver, PropertyPlaceholderResolver
An application context extends a BeanContext and adds the concepts of configuration, environments and
runtimes.
The ApplicationContext is the main entry point for starting and running Micronaut applications. It
can be thought of as a container object for all dependency injected objects.
The ApplicationContext can be started via the run() method. For example:
ApplicationContext context = ApplicationContext.run();
Alternatively, the build() method can be used to customize the ApplicationContext using the ApplicationContextBuilder interface
prior to running. For example:
ApplicationContext context = ApplicationContext.build().environments("test").start();
The getEnvironment() method can be used to obtain a reference to the application Environment, which contains the loaded configuration
and active environment names.
ApplicationContextBuilder,
EnvironmentPropertyPlaceholderResolver.PlaceholderDEFAULT| Modifier and Type | Method and Description |
|---|---|
static ApplicationContextBuilder |
build()
Build a
ApplicationContext. |
static ApplicationContextBuilder |
build(ClassLoader classLoader,
String... environments)
Build a
ApplicationContext. |
static ApplicationContextBuilder |
build(Class mainClass,
String... environments)
Build a
ApplicationContext. |
static ApplicationContextBuilder |
build(Map<String,Object> properties,
String... environments)
Build a
ApplicationContext. |
static ApplicationContextBuilder |
build(String... environments)
Build a
ApplicationContext. |
default ApplicationContext |
environment(Consumer<Environment> consumer)
Allow configuration the
Environment. |
ConversionService<?> |
getConversionService() |
Environment |
getEnvironment() |
default <T> ApplicationContext |
registerSingleton(Class<T> type,
T singleton)
Registers a new singleton bean at runtime.
|
default <T> ApplicationContext |
registerSingleton(Class<T> type,
T singleton,
Qualifier<T> qualifier)
Registers a new singleton bean at runtime.
|
<T> ApplicationContext |
registerSingleton(Class<T> type,
T singleton,
Qualifier<T> qualifier,
boolean inject)
Registers a new singleton bean at runtime.
|
default ApplicationContext |
registerSingleton(Object singleton)
Registers a new singleton bean at runtime.
|
default ApplicationContext |
registerSingleton(Object singleton,
boolean inject)
Registers a new singleton bean at runtime.
|
static ApplicationContext |
run()
Run the
ApplicationContext. |
static <T extends AutoCloseable> |
run(Class<T> type,
Map<String,Object> properties,
String... environments)
Run the
ApplicationContext with the given type. |
static <T extends AutoCloseable> |
run(Class<T> type,
PropertySource propertySource,
String... environments)
Run the
ApplicationContext with the given type. |
static <T extends AutoCloseable> |
run(Class<T> type,
String... environments)
Run the
ApplicationContext with the given type. |
static ApplicationContext |
run(ClassLoader classLoader,
String... environments)
Run the
BeanContext. |
static ApplicationContext |
run(Map<String,Object> properties,
String... environments)
Run the
ApplicationContext with the given type. |
static ApplicationContext |
run(PropertySource properties,
String... environments)
Run the
ApplicationContext with the given type. |
static ApplicationContext |
run(String... environments)
Run the
ApplicationContext. |
ApplicationContext |
start()
Starts the application context.
|
ApplicationContext |
stop()
Stops the application context.
|
build, createBean, createBean, createBean, createBean, createBean, createBean, destroyBean, getClassLoader, inject, refreshBean, runfindExecutableMethod, findExecutionHandle, findExecutionHandle, findExecutionHandle, findProxyTargetMethod, getExecutableMethod, getExecutionHandle, getExecutionHandle, getProxyTargetMethodfindBean, findBean, findOrInstantiateBean, getBean, getBean, getBeansOfType, getBeansOfType, getProxyTargetBean, streamOfType, streamOfTypecontainsBean, containsBean, findBeanConfiguration, findBeanDefinition, findBeanDefinition, findBeanRegistration, findProxyBeanDefinition, findProxyTargetBeanDefinition, getActiveBeanRegistrations, getActiveBeanRegistrations, getAllBeanDefinitions, getBeanDefinition, getBeanDefinition, getBeanDefinitionReferences, getBeanDefinitions, getBeanDefinitions, getBeanDefinitions, getBeanRegistrations, getProxyTargetBeanDefinitionpublishEventresolveMetadata, resolveMetadatacontainsProperties, containsProperty, get, getProperties, getProperties, getProperty, getProperty, getProperty, getProperty, getProperty, getRequiredProperty, nameOfget, get, getgetPrefix, resolvePlaceholders, resolvePropertyNames, resolveRequiredPlaceholdersConversionService<?> getConversionService()
Environment getEnvironment()
ApplicationContext start()
start in interface LifeCycle<BeanContext>ApplicationContext stop()
stop in interface LifeCycle<BeanContext><T> ApplicationContext registerSingleton(Class<T> type, T singleton, Qualifier<T> qualifier, boolean inject)
BeanDefinitionRegistryRegisters a new singleton bean at runtime. This method expects that the bean definition data will have been compiled ahead of time.
If bean definition data is found the method will perform dependency injection on the instance followed by
invoking any PostConstruct hooks.
If no bean definition data is found the bean is registered as is.
registerSingleton in interface BeanContextregisterSingleton in interface BeanDefinitionRegistryT - The concrete typetype - The bean typesingleton - The singleton beanqualifier - The bean qualifierinject - Whether the singleton should be injected (defaults to true)default <T> ApplicationContext registerSingleton(Class<T> type, T singleton, Qualifier<T> qualifier)
BeanDefinitionRegistryRegisters a new singleton bean at runtime. This method expects that the bean definition data will have been compiled ahead of time.
If bean definition data is found the method will perform dependency injection on the instance followed by
invoking any PostConstruct hooks.
If no bean definition data is found the bean is registered as is.
registerSingleton in interface BeanContextregisterSingleton in interface BeanDefinitionRegistryT - The concrete typetype - The bean typesingleton - The singleton beanqualifier - The bean qualifierdefault <T> ApplicationContext registerSingleton(Class<T> type, T singleton)
BeanDefinitionRegistryRegisters a new singleton bean at runtime. This method expects that the bean definition data will have been compiled ahead of time.
If bean definition data is found the method will perform dependency injection on the instance followed by
invoking any PostConstruct hooks.
If no bean definition data is found the bean is registered as is.
registerSingleton in interface BeanContextregisterSingleton in interface BeanDefinitionRegistryT - The concrete typetype - the bean typesingleton - The singleton beandefault ApplicationContext registerSingleton(Object singleton, boolean inject)
BeanDefinitionRegistryRegisters a new singleton bean at runtime. This method expects that the bean definition data will have been compiled ahead of time.
If bean definition data is found the method will perform dependency injection on the instance followed by
invoking any PostConstruct hooks.
If no bean definition data is found the bean is registered as is.
registerSingleton in interface BeanContextregisterSingleton in interface BeanDefinitionRegistrysingleton - The singleton beaninject - Whether the singleton should be injected (defaults to true)default ApplicationContext environment(Consumer<Environment> consumer)
Environment.consumer - The consumerdefault ApplicationContext registerSingleton(Object singleton)
BeanDefinitionRegistryRegisters a new singleton bean at runtime. This method expects that the bean definition data will have been compiled ahead of time.
If bean definition data is found the method will perform dependency injection on the instance followed by
invoking any PostConstruct hooks.
If no bean definition data is found the bean is registered as is.
registerSingleton in interface BeanContextregisterSingleton in interface BeanDefinitionRegistrysingleton - The singleton beanstatic ApplicationContext run(String... environments)
environments - The environments to useApplicationContextstatic ApplicationContext run()
run in interface BeanContextApplicationContextstatic ApplicationContext run(Map<String,Object> properties, String... environments)
ApplicationContext with the given type. Returning an instance of the type. Note this method
should not be used.
If the ApplicationContext requires graceful shutdown unless the returned bean takes responsibility for
shutting down the context.properties - Additional propertiesenvironments - The environment namesApplicationContextstatic ApplicationContext run(PropertySource properties, String... environments)
ApplicationContext with the given type. Returning an instance of the type. Note this method
should not be used.
If the ApplicationContext requires graceful shutdown unless the returned bean takes responsibility for
shutting down the context.properties - Additional propertiesenvironments - The environment namesApplicationContextstatic <T extends AutoCloseable> T run(Class<T> type, String... environments)
ApplicationContext with the given type. Returning an instance of the type. Note this method
should not be used.
If the ApplicationContext requires graceful shutdown unless the returned bean takes responsibility for
shutting down the context.T - The typetype - The type of the bean to runenvironments - The environments to usestatic <T extends AutoCloseable> T run(Class<T> type, Map<String,Object> properties, String... environments)
ApplicationContext with the given type. Returning an instance of the type. Note this method
should not be used.
If the ApplicationContext requires graceful shutdown unless the returned bean takes responsibility for
shutting down the context.T - The typetype - The type of the bean to runproperties - Additional propertiesenvironments - The environment namesstatic <T extends AutoCloseable> T run(Class<T> type, PropertySource propertySource, String... environments)
ApplicationContext with the given type. Returning an instance of the type. Note this method
should not be used.
If the ApplicationContext requires graceful shutdown unless the returned bean takes responsibility for
shutting down the context.T - The typetype - The environment to usepropertySource - Additional propertiesenvironments - The environment namesBeanContextstatic ApplicationContextBuilder build(String... environments)
ApplicationContext.environments - The environments to useApplicationContextstatic ApplicationContextBuilder build(Map<String,Object> properties, String... environments)
ApplicationContext.properties - The propertiesenvironments - The environments to useApplicationContextstatic ApplicationContextBuilder build()
ApplicationContext.build in interface BeanContextApplicationContextstatic ApplicationContext run(ClassLoader classLoader, String... environments)
classLoader - The classloader to useenvironments - The environments to useApplicationContextstatic ApplicationContextBuilder build(ClassLoader classLoader, String... environments)
ApplicationContext.classLoader - The classloader to useenvironments - The environment to useApplicationContextstatic ApplicationContextBuilder build(Class mainClass, String... environments)
ApplicationContext.mainClass - The main class of the applicationenvironments - The environment to useApplicationContext