一.初始化
-
@PostConstruct
-
org.springframework.beans.factory.InitializingBean
接口
void afterPropertiesSet()
-
init-method
属性
二.注销
-
@PreDestroy
-
org.springframework.beans.factory.DisposableBean
接口
void destroy() throws Exception;
- destroy-method属性
三.容器启动和关闭(Startup and shutdown callbacks )
publicinterface Lifecycle {
void start(); void stop(); boolean isRunning(); }
(附:正确关闭非web的spring容器: AbstractApplicationContext.registerShutdownHook())
四. 感知容器
public interface ApplicationContextAware { void setApplicationContext(ApplicationContext applicationContext) throws BeansException; }
public interface ApplicationContextAware} void setApplicationContext(ApplicationContext applicationContext) throws BeansException; }
ServletConfigAware
ServletContextAware
messagesourceAware可感知国际化信息
五. 容器扩展点
-
org.springframework.beans.factory.config.BeanPostProcessor
When such a class is registered as a post-processor with the container, for each bean instance that is created by the container, the post-processor gets a callback from the container both before container initialization methods (such as InitializingBean’s afterPropertiesSet() and any declared init method) are called as well as after any bean initialization callbacks
-
org.springframework.beans.factory.config.BeanFactoryPostProcessor
BeanFactoryPostProcessor
operates on the bean configuration metadata; that is, the Spring IoC container allows a BeanFactoryPostProcessor
to read the configuration metadata and potentially change it before the container instantiates any beans other than BeanFactoryPostProcessors
.
-------》PropertyPlaceholderConfigurer,PropertyOverrideConfigurer