Spring core source code, the Spring core architecture diagram, which contains calls between various classes and APIS, introduces another point, the spring core things again comb through

Spring Bean life cycle, from create -› use -› Destroy

You define a bunch of beans in your system using XML or annotations

(1) Instantiate beans: If you want to use a Bean

(2) Set object properties (dependency injection) : he needs to see who your bean depends on, create your bean dependency, and give you an injection, such as through a constructor, setter

(3) Processing Aware interface:

If the Bean already implements the ApplicationContextAware interface, the Spring container calls our Bean’s setApplicationContext(ApplicationContext) method, passing in the Spring context, Pass the Spring container to this bean

(4) BeanPostProcessor

If we want to do some custom processing on the bean after the bean instance is built, at this point in time, we can have the bean implement the BeanPostProcessor interface, That will be invoked postProcessBeforeInitialization (Object obj, String s) method.

(5) InitializingBean and init-method:

If the Bean has the init-method property configured in the Spring configuration file, its configured initialization method is automatically called.

(6) if the Bean implements the BeanPostProcessor interface, will call postProcessAfterInitialization (Object obj, String s) method

(7) DisposableBean:

When the Bean is no longer needed, it passes through the DisposableBean stage. If the Bean implements the Interface DisposableBean, its implementation destroy() method will be called;

(8) destroy-method:

Finally, if the Bean has the destroy-method property configured in its Spring configuration, its configured destruction method is automatically called.

Create + initialize a bean -› Spring container-managed beans live long term › destroy beans (two callback functions)