spring bean创建之后和销毁之前
spring bean在创建之后和销毁之前的赋能,两种实现方式
通过注解的方式
@PostConstruct
public void init(){
System.out.println("service init");
}
@PreDestroy
public void destroy(){
System.out.println("service destroy");
}
通过实现接口
public abstract class AbstractService implements InitializingBean, DisposableBean {
@Override
public void afterPropertiesSet() throws Exception {
System.out.println("AbstractService afterPropertiesSet");
}
@Override
public void destroy() throws Exception {
System.out.println("AbstractService destroy");
}
}

浙公网安备 33010602011771号