参考文档:https://docs.spring.io/spring-framework/docs/current/spring-framework-reference/core.html#beans-factory-lifecycle Spring官方文档是这么写的: Multiple lifecycle mechanisms configured for the same bean, with different initialization methods, are called as f
一.通过@Bean指定初始化和销毁方法 在以往的xml中,我们是这样配置的 <bean id="exampleInitBean" class="examples.ExampleBean" init-method="init" destroy-method="cleanup"/> 那如果采用注解 的方式该如何配置呢? 首先我们创建一个Car, public class Car { public Car(){ Syst
BeanPostProcessor我们一般称为Bean的后置处理器,它与我们前面介绍的InitialingBean.init-method等一样,都是在bean的初始化时被调用,具体的用法我们在举例中进行学习. 要使用BeanPostProcessor非常简单,只要实现这个接口即可. 在此之前,我们来先看下我们的Cat类,我们的目的是将这个Cat注册进spring的ioc容器中,并让这个BeanPostProcessor起到作用. public class Cat implements Init