Interface ConfigurableApplicationContext
- All Superinterfaces:
- ApplicationContext, ApplicationEventPublisher, AutoCloseable, BeanFactory, Closeable, EnvironmentCapable, HierarchicalBeanFactory, Lifecycle, ListableBeanFactory, MessageSource, ResourceLoader, ResourcePatternResolver
- All Known Subinterfaces:
- ConfigurableWebApplicationContext
- All Known Implementing Classes:
- AbstractApplicationContext, AbstractRefreshableApplicationContext, AbstractRefreshableConfigApplicationContext, AbstractRefreshableWebApplicationContext, AbstractXmlApplicationContext, AnnotationConfigApplicationContext, AnnotationConfigWebApplicationContext, ClassPathXmlApplicationContext, FileSystemXmlApplicationContext, GenericApplicationContext, GenericGroovyApplicationContext, GenericWebApplicationContext, GenericXmlApplicationContext, GroovyWebApplicationContext, StaticApplicationContext, StaticWebApplicationContext, XmlWebApplicationContext
ApplicationContext interface.
Configuration and lifecycle methods are encapsulated here to avoid making them obvious to ApplicationContext client code. The present methods should only be used by startup and shutdown code.
- Since:
- 03.11.2003
- Author:
- Juergen Hoeller, Chris Beams, Sam Brannen
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic final StringName of theApplicationStartupbean in the factory: "applicationStartup".static final StringThe name of the bootstrap executor bean in the context: "bootstrapExecutor".static final StringAny number of these characters are considered delimiters between multiple context config paths in a singleStringvalue: ",; \t\n".static final StringName of theConversionServicebean in the factory: "conversionService".static final StringName of theEnvironmentbean in the factory: "environment".static final StringName of theLoadTimeWeaverbean in the factory: "loadTimeWeaver".static final StringName of the shutdown hook thread: "SpringContextShutdownHook".static final StringName of the Operating System environment bean in the factory: "systemEnvironment".static final StringName of the JVM System properties bean in the factory: "systemProperties".Fields inherited from interface BeanFactoryFACTORY_BEAN_PREFIX, FACTORY_BEAN_PREFIX_CHARFields inherited from interface ResourceLoaderCLASSPATH_URL_PREFIXFields inherited from interface ResourcePatternResolverCLASSPATH_ALL_URL_PREFIX
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddApplicationListener(ApplicationListener<?> listener) Add a new ApplicationListener that will be notified on context events such as context refresh and context shutdown.voidaddBeanFactoryPostProcessor(BeanFactoryPostProcessor postProcessor) Add a new BeanFactoryPostProcessor that will get applied to the internal bean factory of this application context on refresh, before any of the bean definitions get evaluated.voidaddProtocolResolver(ProtocolResolver resolver) Register the given protocol resolver with this application context, allowing for additional resource protocols to be handled.voidclose()Close this application context, releasing all resources and locks that the implementation might hold.Return theApplicationStartupfor this application context.Return the internal bean factory of this application context.Return theEnvironmentfor this application context in configurable form, allowing for further customization.booleanisActive()Determine whether this application context is active, that is, whether it has been refreshed at least once and has not been closed yet.booleanisClosed()Return whether this context has been closed already, that is, whetherclose()has been called on an active context in order to initiate its shutdown.voidpause()Stop all beans in this application context unless they explicitly opt out of pausing throughSmartLifecycle.isPauseable()returningfalse.voidrefresh()Load or refresh the persistent representation of the configuration, which might be from Java-based configuration, an XML file, a properties file, a relational database schema, or some other format.voidRegister a shutdown hook with the JVM runtime, closing this context on JVM shutdown unless it has already been closed at that time.voidremoveApplicationListener(ApplicationListener<?> listener) Remove the given ApplicationListener from this context's set of listeners, assuming it got registered viaaddApplicationListener(ApplicationListener)before.voidrestart()Pause all beans in this application context if necessary, and subsequently restart all auto-startup beans, effectively restoring the lifecycle state afterrefresh()(typically after a precedingpause()call when a fullLifecycle.start()of even lazy-starting beans is to be avoided).voidsetApplicationStartup(ApplicationStartup applicationStartup) Set theApplicationStartupfor this application context.voidsetClassLoader(ClassLoader classLoader) Specify the ClassLoader to load class path resources and bean classes with.voidsetEnvironment(ConfigurableEnvironment environment) Set theEnvironmentfor this application context.voidSet the unique ID of this application context.voidsetParent(@Nullable ApplicationContext parent) Set the parent of this application context.Methods inherited from interface ApplicationContextgetApplicationName, getAutowireCapableBeanFactory, getDisplayName, getId, getParent, getStartupDateMethods inherited from interface ApplicationEventPublisherpublishEvent, publishEventMethods inherited from interface BeanFactorycontainsBean, getAliases, getBean, getBean, getBean, getBean, getBean, getBeanProvider, getBeanProvider, getBeanProvider, getType, getType, isPrototype, isSingleton, isTypeMatch, isTypeMatchMethods inherited from interface HierarchicalBeanFactorycontainsLocalBean, getParentBeanFactoryMethods inherited from interface ListableBeanFactorycontainsBeanDefinition, findAllAnnotationsOnBean, findAnnotationOnBean, findAnnotationOnBean, getBeanDefinitionCount, getBeanDefinitionNames, getBeanNamesForAnnotation, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanNamesForType, getBeanProvider, getBeanProvider, getBeansOfType, getBeansOfType, getBeansWithAnnotationMethods inherited from interface MessageSourcegetMessage, getMessage, getMessageMethods inherited from interface ResourceLoadergetClassLoader, getResourceMethods inherited from interface ResourcePatternResolvergetResources
- 
Field Details- 
CONFIG_LOCATION_DELIMITERSAny number of these characters are considered delimiters between multiple context config paths in a singleStringvalue: ",; \t\n".- See Also:
 
- 
BOOTSTRAP_EXECUTOR_BEAN_NAMEThe name of the bootstrap executor bean in the context: "bootstrapExecutor".If none is supplied, no background bootstrapping will be active. - Since:
- 6.2
- See Also:
 
- 
CONVERSION_SERVICE_BEAN_NAMEName of theConversionServicebean in the factory: "conversionService".If none is supplied, default conversion rules apply. - Since:
- 3.0
- See Also:
 
- 
LOAD_TIME_WEAVER_BEAN_NAMEName of theLoadTimeWeaverbean in the factory: "loadTimeWeaver".If such a bean is supplied, the context will use a temporary ClassLoaderfor type matching, in order to allow theLoadTimeWeaverto process all actual bean classes.- Since:
- 2.5
- See Also:
 
- 
ENVIRONMENT_BEAN_NAMEName of theEnvironmentbean in the factory: "environment".- Since:
- 3.1
- See Also:
 
- 
SYSTEM_PROPERTIES_BEAN_NAMEName of the JVM System properties bean in the factory: "systemProperties".- See Also:
 
- 
SYSTEM_ENVIRONMENT_BEAN_NAMEName of the Operating System environment bean in the factory: "systemEnvironment".- See Also:
 
- 
APPLICATION_STARTUP_BEAN_NAMEName of theApplicationStartupbean in the factory: "applicationStartup".- Since:
- 5.3
- See Also:
 
- 
SHUTDOWN_HOOK_THREAD_NAMEName of the shutdown hook thread: "SpringContextShutdownHook".- Since:
- 5.2
- See Also:
 
 
- 
- 
Method Details- 
setId
- 
setParentSet the parent of this application context.Note that the parent shouldn't be changed: It should only be set outside a constructor if it isn't available when an object of this class is created, for example in case of WebApplicationContext setup. - Parameters:
- parent- the parent context
- See Also:
 
- 
setEnvironmentSet theEnvironmentfor this application context.- Parameters:
- environment- the new environment
- Since:
- 3.1
 
- 
getEnvironmentConfigurableEnvironment getEnvironment()Return theEnvironmentfor this application context in configurable form, allowing for further customization.- Specified by:
- getEnvironmentin interface- EnvironmentCapable
- Since:
- 3.1
 
- 
setApplicationStartupSet theApplicationStartupfor this application context.This allows the application context to record metrics during startup. - Parameters:
- applicationStartup- the new context event factory
- Since:
- 5.3
 
- 
getApplicationStartupApplicationStartup getApplicationStartup()Return theApplicationStartupfor this application context.- Since:
- 5.3
 
- 
addBeanFactoryPostProcessorAdd a new BeanFactoryPostProcessor that will get applied to the internal bean factory of this application context on refresh, before any of the bean definitions get evaluated. To be invoked during context configuration.- Parameters:
- postProcessor- the factory processor to register
 
- 
addApplicationListenerAdd a new ApplicationListener that will be notified on context events such as context refresh and context shutdown.Note that any ApplicationListener registered here will be applied on refresh if the context is not active yet, or on the fly with the current event multicaster in case of a context that is already active. - Parameters:
- listener- the ApplicationListener to register
- See Also:
 
- 
removeApplicationListenerRemove the given ApplicationListener from this context's set of listeners, assuming it got registered viaaddApplicationListener(ApplicationListener)before.- Parameters:
- listener- the ApplicationListener to deregister
- Since:
- 6.0
 
- 
setClassLoaderSpecify the ClassLoader to load class path resources and bean classes with.This context class loader will be passed to the internal bean factory. - Since:
- 5.2.7
- See Also:
 
- 
addProtocolResolverRegister the given protocol resolver with this application context, allowing for additional resource protocols to be handled.Any such resolver will be invoked ahead of this context's standard resolution rules. It may therefore also override any default rules. - Since:
- 4.3
 
- 
refreshLoad or refresh the persistent representation of the configuration, which might be from Java-based configuration, an XML file, a properties file, a relational database schema, or some other format.As this is a startup method, it should destroy already created singletons if it fails, to avoid dangling resources. In other words, after invocation of this method, either all or no singletons at all should be instantiated. - Throws:
- BeansException- if the bean factory could not be initialized
- IllegalStateException- if already initialized and multiple refresh attempts are not supported
 
- 
restartvoid restart()Pause all beans in this application context if necessary, and subsequently restart all auto-startup beans, effectively restoring the lifecycle state afterrefresh()(typically after a precedingpause()call when a fullLifecycle.start()of even lazy-starting beans is to be avoided).- Since:
- 7.0
- See Also:
 
- 
pausevoid pause()Stop all beans in this application context unless they explicitly opt out of pausing throughSmartLifecycle.isPauseable()returningfalse.- Since:
- 7.0
- See Also:
 
- 
registerShutdownHookvoid registerShutdownHook()Register a shutdown hook with the JVM runtime, closing this context on JVM shutdown unless it has already been closed at that time.This method can be called multiple times. Only one shutdown hook (at max) will be registered for each context instance. The name of the shutdown hook thread should be SHUTDOWN_HOOK_THREAD_NAME.- See Also:
 
- 
closevoid close()Close this application context, releasing all resources and locks that the implementation might hold. This includes destroying all cached singleton beans.Note: Does not invoke closeon a parent context; parent contexts have their own, independent lifecycle.This method can be called multiple times without side effects: Subsequent closecalls on an already closed context will be ignored.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
 
- 
isClosedboolean isClosed()Return whether this context has been closed already, that is, whetherclose()has been called on an active context in order to initiate its shutdown.Note: This does not indicate whether context shutdown has completed. Use isActive()for differentiating between those scenarios: a context becomes inactive once it has been fully shut down and the originalclose()call has returned.- Since:
- 6.2
 
- 
isActiveboolean isActive()Determine whether this application context is active, that is, whether it has been refreshed at least once and has not been closed yet.- Returns:
- whether the context is still active
- See Also:
 
- 
getBeanFactoryReturn the internal bean factory of this application context. Can be used to access specific functionality of the underlying factory.Note: Do not use this to post-process the bean factory; singletons will already have been instantiated before. Use a BeanFactoryPostProcessor to intercept the BeanFactory setup process before beans get touched. Generally, this internal factory will only be accessible while the context is active, that is, in-between refresh()andclose(). TheisActive()flag can be used to check whether the context is in an appropriate state.- Returns:
- the underlying bean factory
- Throws:
- IllegalStateException- if the context does not hold an internal bean factory (usually if- refresh()hasn't been called yet or if- close()has already been called)
- See Also:
 
 
-