1.ApplicationContextAware
https://blog.csdn.net/bailinbbc/article/details/76446594
实现此接口的类,spring容器会在创建该类为Bean之后(即 new Class),自动调用该Bean的setApplicationContext()方法
var1内为上下文,可以获取上下文,当前bena的id。
(先实例化 即 new class(), 再初始化 即对对象的值赋一下初始值. 可详见 https://blog.csdn.net/justloveyou_/article/details/72466416)
public interface ApplicationContextAware extends Aware {
void setApplicationContext(ApplicationContext var1) throws BeansException;
}
2.BeanFactoryPostProcessor
https://blog.csdn.net/baidu_19473529/article/details/81152109
实现此接口的类,允许我们在工厂里所有的bean被加载进来后但是还没初始化前,对所有bean的属性进行修改也可以add属性值。
即再实例化之后,自动调用该bean的postProcessBeanFactory 方法..
执行顺序,若同时继承了ApplicationContextAware.则执行顺序在其后
public interface BeanFactoryPostProcessor {
void postProcessBeanFactory(ConfigurableListableBeanFactory var1) throws BeansException;
}
3.BeanPostProcessor
https://www.cnblogs.com/sishang/p/6576665.html
实现此接口的类,提供了两个方法,允许我们在两个特定的时间节点做对应的操作.
会遍历出整个工厂里所有的bean.(有些已经被处理或取出的bean不会被遍历.)
例如,在 1当中, Map<String, Object> objs = applicationContext.getBeansWithAnnotation(Aspect.class);
则所有带Aspect切面的类都不会被遍历到.
执行顺序.
在BeanFactoryPostProcessor.postProcessBeanFactory之后,两个方法的时间节点如下.都是实例化后,一个是初始化前,一个初始化后.
若有多个类实现了此接口,则执行的顺序为, 依照对应类的字母顺序.来决定执行先后.
如果不是实现类不是通过注解的,而是通过XML文件定义的,则按照定义的先后顺序来执行.
public interface BeanPostProcessor {
/**
* Apply this BeanPostProcessor to the given new bean instance <i>before</i> any bean
* initialization callbacks (like InitializingBean's {@code afterPropertiesSet}
* or a custom init-method). The bean will already be populated with property values.
*/
//实例化、依赖注入完毕,在调用显示的初始化之前完成一些定制的初始化任务
Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException;
/**
* Apply this BeanPostProcessor to the given new bean instance <i>after</i> any bean
* initialization callbacks (like InitializingBean's {@code afterPropertiesSet}
* or a custom init-method). The bean will already be populated with property values.
*/
//实例化、依赖注入、初始化完毕时执行
Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException;
}
4.ApplicationRunner
https://www.cnblogs.com/javafucker/p/9719239.html
在工程中启动的时机为系统打印出 当前系统 启动耗时之前,
Started totalController in 1.688 seconds (JVM running for 2.512)
public interface ApplicationRunner {
void run(ApplicationArguments var1) throws Exception;
}