Reference https://www.cnblogs.com/liran123/p/9409763.html
1, instantiation of a bean--is what we often say new;
2. Attribute injection to the bean according to the spring context
3, if the bean has implemented the Beannameaware interface, it will invoke its implementation of the Setbeanname (String) method, which is passed in the spring configuration file, the Bean ID value
4, if the bean has implemented the Beanfactoryaware interface, it will invoke its implementation of the Setbeanfactory (Setbeanfactory (beanfactory) The spring factory itself is passed (this is the way to get the other beans, just configure a normal bean in the Spring config file);
5, if the bean has implemented the Applicationcontextaware interface, it will call the Setapplicationcontext (ApplicationContext) method, Passing in the spring context (same way can also implement step 4 content, but better than 4, because ApplicationContext is beanfactory sub-interface, there are more implementation methods);
6. If the bean is associated with the Beanpostprocessor interface, the postprocessbeforeinitialization (Object obj, String s) method is called, Beanpostprocessor is often used as a change to the bean content, and because it is called at the end of the bean initialization process, it can also be applied to memory or cache technology;
7. If the bean is configured in the spring configuration file, the Init-method property automatically invokes its configured initialization method.
8. If the bean is associated with the Beanpostprocessor interface, the postprocessafterinitialization (Object obj, String s) method is called. If the bean implements the Initializingbean interface, Spring will invoke its Afterpropertiesset interface method.
Note: After the completion of the work can be applied to the bean, the Bean is a singleton, so generally we call the same ID of the bean will be in the same content address instance, of course, in the spring configuration file can also be configured non-singleton, Here we do not repeat.
9, when the bean is no longer needed, it will go through the cleanup phase, if the Bean implements Disposablebean this interface, will call that its implementation of the Destroy () method;
10. Finally, if the Destroy-method attribute is configured in the spring configuration of this bean, its configured destruction method is automatically invoked.
This describes the life cycle of applying the spring context bean, and if you apply Spring's factory, which is Beanfactory, remove the 5th step and OK.
The Bean's life cycle in spring