public class Car {
public Car(){
System.out.println("无参构造......");}
public void init(){
System.out.println("car 初始化调用....");}
public void destroy(){
System.out.println("car 销毁时调用");}}
public class Cat implements InitializingBean, DisposableBean {
public Cat(){
System.out.println("Cat");}
/**定义销毁时逻辑*/
public void destroy() throws Exception {
System.out.println("销毁时");}
/**容器加载完成后*/
public void afterPropertiesSet() throws Exception {
System.out.println("初始化时");}}
public class Dog {
public Dog(){
System.out.println("Dog");}
@PostConstruct
public void init(){
System.out.println("Dog 容器创建完成并且属性赋值完成,初始化方法");}
@PreDestroy
public void destroy(){
System.out.println("Dog 容器销毁bean之前通知我们进行清理工作.....");}}
@Configuration
public class MainConfigLifeCycle {
@Bean(initMethod ="init",destroyMethod ="destroy")
public Car car(){return new Car();}
@Bean
public Cat cat(){return new Cat();}
@Bean
public Dog dog(){return new Dog();}}