13、生命周期-InitializingBean和DisposableBean

匿名 (未验证) 提交于 2019-12-03 00:05:01
package com.lei.study_09_15.bean;  import org.springframework.beans.factory.DisposableBean; import org.springframework.beans.factory.InitializingBean;  /**  *  *  * @author LeiLei  * @date 2019/9/15  */ public class Cat implements InitializingBean,DisposableBean {      public Cat() {         System.out.println("Cat.Cat");     }      public void destroy() throws Exception {         System.out.println("Cat.destroy");      }      /**      * 相当于init方法      * @throws Exception      */     public void afterPropertiesSet() throws Exception {         System.out.println("Cat.afterPropertiesSet");      } } 

总结:

1.容器初始化管理用实现接口的方式来实现。 

2.afterPropertiesSet相当于@Bean中的init方法。

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!