spring 技巧

ApplicationContextAware

实现该接口,获取获取spring的bean。

InitializingBean ,DisposableBean

实现该接口,可以在bean初始化和销毁前进行操作

BeanPostProcessor

实现该接口,

BeanPostProcessor也称为Bean后置处理器,它是Spring中定义的接口,在Spring容器的创建过程中(具体为Bean初始化前后)会回调BeanPostProcessor中定义的两个方法。

public interface BeanPostProcessor {


    Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException;

    
    Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException;

}

我们可以通过这俩个接口来进行一些操作,比如说我们可以通过自定义注解,找到对应的字段上是否有这个注解,然后可以手动注入属性。

你可能感兴趣的:(Java)