源码解析:init-method、@PostConstruct、afterPropertiesSet孰先孰后
2013-05-29 10:14
417 查看
Spring 容器中的 Bean 是有生命周期的,Spring 允许在 Bean 在初始化完成后以及Bean 销毁前执行特定的操作,常用的设定方式有以下三种:
通过实现InitializingBean/DisposableBean 接口来定制初始化之后/销毁之前的操作方法;
通过<bean> 元素的 init-method/destroy-method属性指定初始化之后 /销毁之前调用的操作方法;
在指定方法上加上@PostConstruct或@PreDestroy注解来制定该方法是在初始化之后还是销毁之前调用。
这是我们就有个疑问,这三种方式是完全等同的吗,孰先孰后?
最后,给出本文的结论,Bean在实例化的过程中:
Constructor > @PostConstruct >InitializingBean > init-method
http://sexycoding.iteye.com/blog/1046993
通过实现InitializingBean/DisposableBean 接口来定制初始化之后/销毁之前的操作方法;
通过<bean> 元素的 init-method/destroy-method属性指定初始化之后 /销毁之前调用的操作方法;
在指定方法上加上@PostConstruct或@PreDestroy注解来制定该方法是在初始化之后还是销毁之前调用。
这是我们就有个疑问,这三种方式是完全等同的吗,孰先孰后?
最后,给出本文的结论,Bean在实例化的过程中:
Constructor > @PostConstruct >InitializingBean > init-method
http://sexycoding.iteye.com/blog/1046993
相关文章推荐
- 源码解析:init-method、@PostConstruct、afterPropertiesSet孰先孰后
- 【Spring源码】从源码实现的角度解析spring的InitializingBean的afterPropertiesSet方法和init-method区别和应用
- Spring InitializingBean的afterPropertiesSet与init-method、@PostConstruct
- 写代码简单比较init-method,afterPropertiesSet和BeanPostProcessor
- init-method 与afterPropertiesSet
- Spring的init-method 与afterPropertiesSet
- spring的InitializingBean的 afterPropertiesSet 方法 和 init-method配置的 区别联系
- spring中afterPropertiesSet方法与init-method配置描述
- spring bean中构造函数,afterPropertiesSet和init-method的执行顺序
- 【转】比较init-method,afterPropertiesSet和BeanPostProcessor
- 简单比较init-method,afterPropertiesSet和BeanPostProcessor
- spring的InitializingBean的 afterPropertiesSet 方法 和 init-method配置的区别联系
- spring的InitializingBean的 afterPropertiesSet 方法 和 init-method配置的 区别联系
- 简单比较init-method,afterPropertiesSet和BeanPostProcessor
- 写代码简单比较init-method,afterPropertiesSet和BeanPostProcessor
- spring @postConstruct init-method constructor和afterSetProperties() 执行顺序
- Spring启动,constructor,@PostConstruct,afterPropertiesSet,onApplicationEvent执行顺序
- Spring启动,constructor,@PostConstruct,afterPropertiesSet,onApplicationEvent执行顺序 原创 2016年09月29日 11:39:2
- initMethod 和 afterPropertiesSet 以及 AwareMethod方法的执行时机
- HashSet<T> 源码解析