0 0 0 0

Before verifying the spring bean initialization order, look at several key interfaces


Spirng 's InitializingBean provides a way to define initialization methods for beans.. InitializingBean is an interface that contains only one method: AfterPropertiesSet ( )..

After spring initialization, all the property settings ( that's, setXXX ) will automatically call the afterPropertiesSet ( ), in the configuration file, no special configuration

Init-method ( )

Spring can do a callback to this bean after InitializingBean is initialized, but this approach requires a bean to implement the InitializingBean interface.. One but the bean implements the InitializingBean interface, then the bean 's code is coupled with spring.. Typically, I don't encourage beans to implement the InitializingBean directly, using the functionality of the initialization method provided by spring to perform a..

BeanFactoryPostProcessor interface

You can modify the definition properties of a bean before spring beans can be created.. That's, spring allows BeanFactoryPostProcessor to read configuration metadata before the container I & tantiate any other bean, and can be modified as needed, such as changing the scope of the bean from the kernel to the.. You can configure multiple BeanFactoryPostProcessor s simultaneously and control the execution order of each BeanFactoryPostProcessor by setting the order property..

Note: after the spring container loads the definition file for the bean, it's executed before the bean I & tantiation.. Interface method into configurrablelistablebeanfactory, using this parameter to get the definition information of the associated bean..

BeanPostProcessor interface

After the spring container I & tantiate the bean, add some of its own processing logic before executing the bean initialization method.. The initialization method described here refers to the following two:

1 ) the bean implements the InitializingBean interface, and the corresponding method is afterPropertiesSet

2 ) methods set by the init method when the bean definition is defined

Note: the BeanPostProcessor is the definition file that's executed after the spring container loads the bean and instantiate the bean.. The order of execution of BeanPostProcessor is after BeanFactoryPostProcessor..

Initialize bean order

1 co tructor

2. Initialization properties.

3. If implemented, the BeanFactoryAware interface performs the setBeanFactory method..

4. If the InitializingBean interface is implemented, the afterPropertiesSet method is executed..

5 if the init method is specified in the configuration file, then perform this method

6. If the BeanFactoryPostProcessor interface is implemented, the postProcessBeanFactory method is executed before the new class. ( this method can change the configuration of attribute values in the configuration file. ).

7 if the BeanPostProcessor interface is implemented, the postProcessBeforeInitialization method is executed before other bean initialization methods, followed by the postProcessAfterInitialization method..

The weird thing is, there's no destroy method..

There's no way to execute the interface BeanPostProcessor in this method, and I don't know

Copyright © 2011 Dowemo All rights reserved.    Creative Commons   AboutUs