Multiple lifecycle mechanisms configured for the same bean, with different initialization methods, are called as follows: Methods annotated with @PostConstruct afterPropertiesSet() as defined by the InitializingBean callback interface A custom…
一.通过@Bean指定初始化和销毁方法 在以往的xml中,我们是这样配置的 <bean id="exampleInitBean" class="examples.ExampleBean" init-method="init" destroy-method="cleanup"/> 那如果采用注解 的方式该如何配置呢? 首先我们创建一个Car, public class Car { public Car(){ Syst…
一 指定初始化和销毁方法 通过@Bean指定init-method和destroy-method: @Bean(initMethod="init",destroyMethod="detory") public Car car(){ return new Car(); } 二 通过让Bean实现InitializingBean(定义初始化逻辑) @Component public class Cat implements InitializingBean,Dispos…
可以使用bean的init-method和destroy-method属性来初始化和销毁bean.定义一个Hero类: package com.moonlit.myspring; public class Hero { public void born() { System.out.println("the hero is born."); } public void defaultBorn() { System.out.println("the hero is born b…