public class DefaultApplicationContext extends DefaultBeanContext implements ApplicationContext
ApplicationContext interface.initializing, LOG, LOG_LIFECYCLE, running, terminatingEMPTYDEFAULT| Constructor and Description |
|---|
DefaultApplicationContext(ApplicationContextConfiguration configuration)
Construct a new ApplicationContext for the given environment name and classloader.
|
DefaultApplicationContext(ClassPathResourceLoader resourceLoader,
String... environmentNames)
Construct a new ApplicationContext for the given environment name and classloader.
|
DefaultApplicationContext(String... environmentNames)
Construct a new ApplicationContext for the given environment name.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
containsProperties(String name)
Whether the given property or any nested properties exist for the key given key within this resolver.
|
boolean |
containsProperty(String name)
Whether the given property is contained within this resolver.
|
protected ConversionService |
createConversionService()
Creates the default conversion service.
|
protected DefaultEnvironment |
createEnvironment(ApplicationContextConfiguration configuration)
Creates the default environment for the given environment name.
|
protected DefaultEnvironment |
createEnvironment(String... environmentNames)
Deprecated.
|
protected <T> Collection<BeanDefinition<T>> |
findBeanCandidates(Class<T> beanType,
BeanDefinition<?> filter,
boolean filterProxied)
Find bean candidates for the given type.
|
protected <T> BeanDefinition<T> |
findConcreteCandidate(Class<T> beanType,
Qualifier<T> qualifier,
Collection<BeanDefinition<T>> candidates)
Fall back method to attempt to find a candidate for the given definitions.
|
ConversionService<?> |
getConversionService() |
Environment |
getEnvironment() |
Map<String,Object> |
getProperties(String name,
StringConvention keyFormat)
Return all the properties under the given key.
|
<T> Optional<T> |
getProperty(String name,
ArgumentConversionContext<T> conversionContext)
Resolve the given property for the given name, type and generic type arguments.
|
protected void |
initializeContext(List<BeanDefinitionReference> contextScopeBeans,
List<BeanDefinitionReference> processedBeans)
Initialize the context with the given
Context scope beans. |
protected void |
initializeTypeConverters(BeanContext beanContext) |
protected void |
registerConfiguration(BeanConfiguration configuration)
Registers an active configuration.
|
<T> ApplicationContext |
registerSingleton(Class<T> type,
T singleton,
Qualifier<T> qualifier,
boolean inject)
Registers a new singleton bean at runtime.
|
protected Iterable<BeanConfiguration> |
resolveBeanConfigurations()
Resolves the
BeanConfiguration class instances. |
protected List<BeanDefinitionReference> |
resolveBeanDefinitionReferences()
Resolves the
BeanDefinitionReference class instances. |
Optional<String> |
resolvePlaceholders(String str)
Resolve the placeholders and return an Optional String if it was possible to resolve them.
|
String |
resolveRequiredPlaceholders(String str)
Resolve the placeholders and return an Optional String if it was possible to resolve them.
|
ApplicationContext |
start()
The start method will read all bean definition classes found on the classpath and initialize any pre-required
state.
|
protected void |
startEnvironment()
Start the environment.
|
ApplicationContext |
stop()
The close method will shut down the context calling
PreDestroy hooks on loaded
singletons. |
containsBean, createBean, createBean, createBean, createBean, destroyBean, doCreateBean, doCreateBean, findBean, findBean, findBeanCandidates, findBeanCandidatesForInstance, findBeanConfiguration, findBeanDefinition, findBeanRegistration, findExecutableMethod, findExecutionHandle, findExecutionHandle, findExecutionHandle, findProxyBeanDefinition, findProxyTargetBeanDefinition, findProxyTargetMethod, findProxyTargetMethod, getActiveBeanRegistration, getActiveBeanRegistrations, getActiveBeanRegistrations, getAllBeanDefinitions, getBean, getBean, getBean, getBean, getBeanDefinitionReferences, getBeanDefinitions, getBeanDefinitions, getBeanDefinitions, getBeanProvider, getBeanProvider, getBeanRegistrations, getBeansOfType, getBeansOfType, getBeansOfType, getBeansOfType, getClassLoader, getProxyTargetBean, initializeEventListeners, inject, inject, invalidateCaches, isRunning, processParallelBeans, publishEvent, refreshBean, resolveMetadata, streamOfType, streamOfTypeclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbuild, build, build, build, build, environment, registerSingleton, registerSingleton, registerSingleton, registerSingleton, run, run, run, run, run, run, run, runbuild, createBean, createBean, createBean, createBean, createBean, createBean, destroyBean, getClassLoader, inject, refreshBean, runfindExecutableMethod, findExecutionHandle, findExecutionHandle, findExecutionHandle, findProxyTargetMethod, findProxyTargetMethod, getExecutableMethod, getExecutionHandle, getExecutionHandle, getProxyTargetMethod, 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, resolveMetadataget, getProperties, getProperty, getProperty, getProperty, getProperty, getRequiredProperty, nameOfget, get, getgetPrefix, resolveRequiredPlaceholderpublic DefaultApplicationContext(@Nonnull String... environmentNames)
environmentNames - The environment namespublic DefaultApplicationContext(@Nonnull ClassPathResourceLoader resourceLoader, @Nonnull String... environmentNames)
environmentNames - The environment namesresourceLoader - The class loaderpublic DefaultApplicationContext(@Nonnull ApplicationContextConfiguration configuration)
configuration - The application context configuration@Nonnull public <T> ApplicationContext registerSingleton(@Nonnull Class<T> type, @Nonnull T singleton, @Nullable 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 ApplicationContextregisterSingleton in interface BeanContextregisterSingleton in interface BeanDefinitionRegistryregisterSingleton in class DefaultBeanContextT - The concrete typetype - The bean typesingleton - The singleton beanqualifier - The bean qualifierinject - Whether the singleton should be injected (defaults to true)@Nonnull protected Iterable<BeanConfiguration> resolveBeanConfigurations()
DefaultBeanContextBeanConfiguration class instances. Default implementation uses ServiceLoader pattern.resolveBeanConfigurations in class DefaultBeanContext@Nonnull protected List<BeanDefinitionReference> resolveBeanDefinitionReferences()
DefaultBeanContextBeanDefinitionReference class instances. Default implementation uses ServiceLoader pattern.resolveBeanDefinitionReferences in class DefaultBeanContext@Deprecated @Nonnull protected DefaultEnvironment createEnvironment(@Nonnull String... environmentNames)
createEnvironment(ApplicationContextConfiguration) insteadenvironmentNames - The environment name@Nonnull protected DefaultEnvironment createEnvironment(@Nonnull ApplicationContextConfiguration configuration)
configuration - The application context configuration@Nonnull protected ConversionService createConversionService()
@Nonnull public ConversionService<?> getConversionService()
getConversionService in interface ApplicationContext@Nonnull public Environment getEnvironment()
getEnvironment in interface ApplicationContext@Nonnull public ApplicationContext start()
DefaultBeanContextstart in interface ApplicationContextstart in interface LifeCycle<BeanContext>start in class DefaultBeanContext@Nonnull public ApplicationContext stop()
DefaultBeanContextPreDestroy hooks on loaded
singletons.stop in interface ApplicationContextstop in interface LifeCycle<BeanContext>stop in class DefaultBeanContextpublic boolean containsProperty(String name)
PropertyResolverWhether the given property is contained within this resolver.
Note that this method will return false for nested properties. In other words given a key of foo.bar this method will
return false for: resolver.containsProperty("foo")
To check for nested properties using PropertyResolver.containsProperties(String) instead.
containsProperty in interface PropertyResolvername - The name of the propertypublic boolean containsProperties(String name)
PropertyResolvercontainsProperties in interface PropertyResolvername - The name of the propertypublic <T> Optional<T> getProperty(String name, ArgumentConversionContext<T> conversionContext)
PropertyResolverResolve the given property for the given name, type and generic type arguments.
Implementers can choose to implement more intelligent type conversion by analyzing the typeArgument.
getProperty in interface PropertyResolverT - The concrete typename - The nameconversionContext - The conversion context@Nonnull public Map<String,Object> getProperties(@Nullable String name, @Nullable StringConvention keyFormat)
PropertyResolverStringConvention.RAW.getProperties in interface PropertyResolvername - The namekeyFormat - The key format to use for the keys. Default is kebab-case.protected void registerConfiguration(BeanConfiguration configuration)
DefaultBeanContextregisterConfiguration in class DefaultBeanContextconfiguration - The configuration to registerprotected void startEnvironment()
protected void initializeContext(List<BeanDefinitionReference> contextScopeBeans, List<BeanDefinitionReference> processedBeans)
DefaultBeanContextContext scope beans.initializeContext in class DefaultBeanContextcontextScopeBeans - The context scope beansprocessedBeans - The beans that require ExecutableMethodProcessor handlingprotected <T> Collection<BeanDefinition<T>> findBeanCandidates(Class<T> beanType, BeanDefinition<?> filter, boolean filterProxied)
DefaultBeanContextfindBeanCandidates in class DefaultBeanContextT - The bean generic typebeanType - The bean typefilter - A bean definition to filter outfilterProxied - Whether to filter out bean proxy targetsprotected <T> BeanDefinition<T> findConcreteCandidate(Class<T> beanType, Qualifier<T> qualifier, Collection<BeanDefinition<T>> candidates)
DefaultBeanContextfindConcreteCandidate in class DefaultBeanContextT - The generic timebeanType - The bean typequalifier - The qualifiercandidates - The candidatespublic Optional<String> resolvePlaceholders(String str)
PropertyPlaceholderResolverresolvePlaceholders in interface PropertyPlaceholderResolverstr - The placeholder to resolveOptional.empty() if resolution was not possiblepublic String resolveRequiredPlaceholders(String str) throws ConfigurationException
PropertyPlaceholderResolverresolveRequiredPlaceholders in interface PropertyPlaceholderResolverstr - The placeholder to resolveOptional.empty() if resolution was not possibleConfigurationException - If the placeholders could not be resolvedprotected void initializeTypeConverters(BeanContext beanContext)
beanContext - The bean context