Spring 5.x Source trip thirty-nine getBean extension Processor 4.5
Figure no less
InstantiationAwareBeanPostProcessor的postProcessProperties和postProcessPropertyValues
This is what we call it auto-assembly, internal CommonAnnotationBeanPostProcessor
and AutowiredAnnotationBeanPostProcessor
handling processor for injection.
postProcessPropertyValues
It has expired.
In fact, almost all of the processing. So we can be here in your own extensions, objects have got, and what can not do what is right, not specifically demonstrated.
initializeBean of invokeAwareMethods completion of the injection began initialized
Mainly set some properties, there is a more important is BeanFactoryAware
, it can be obtained BeanFactory
.
For example, we own realization one can get this information, it is more simple look like:
applyBeanPostProcessorsBeforeInitialization before initialization
If you return null
, then return directly, that is not to continue to do a deal, so here can actually organize other processors to handle, custom processor directly back null
, he returned.
In fact, that is, for bean
some operations, nothing special.
invokeInitMethods perform initialization method
Mainly the implementation implements InitializingBean
the interface afterPropertiesSet
method:
Some methods invokeCustomInitMethod custom
That is bean
defined in the set initMethodName
:
Real
Just write the definition of a class method:
public class PoJo {
public void init(){
System.out.println("自定义initMethodName");
}
}
Test code
Registered a bean definition is then set InitMethodName
.
@Test
public void invokeCustomInitMethodTest() throws Exception {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
applicationContext.register(MyConfig.class);
AnnotatedBeanDefinition annotatedBeanDefinition=new AnnotatedGenericBeanDefinition(PoJo.class);
annotatedBeanDefinition.setInitMethodName("init");
applicationContext.registerBeanDefinition("myBean",annotatedBeanDefinition);
applicationContext.refresh();
}
After initialization applyBeanPostProcessorsAfterInitialization
And similar treatment before initialization, do not say.
Well, here today, we hope to help study and understand, do not spray the Great God see, understand only their own learning, limited capacity, please excuse.