Spring 的 init-method 和 destory-method


關於在spring  容器初始化 bean 和銷毀前所做的操作定義方式有三種

 

第一種注解:

  通過@PostConstruct 和 @PreDestroy 方法 實現初始化和銷毀bean之前進行的操作

第二種是XML配置:

  通過 在xml中定義init-method 和  destory-method方法

第三種是接口實現:

  通過bean實現InitializingBean和 DisposableBean接口

具體接口和方法如表

Spring Bean 生命周期各階段
相關接口及方法
Bean 自身方法
Bean 本身業務的方法:
配置文件中 init-method 和 destroy-method 指定的方法
Bean 生命周期接口方法
Initial izingBean 接口
DiposableBean 接口
BeanNameAware 接口
ApplicationCantextAware 接口
BeanFac町Aware 接口
其他
容器級生命周期接口方法
(一般稱為“后處理器”)
lnstantiationAwareBeanPostPracessor 接口實現
BeanPostProcessor 接口實現
工廠級生命周期接口方法
(也可以歸為容器級的)
AspecUWeavingEnabler
Con丑gurationC!assPostProcessor
CustomAutowireConfigurer

 

生命周期 序圖 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM