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方法。