Spring START process

Source: Internet
Author: User

Abstractapplicationcontext Analysis

Start process
Prepare this context for refreshing.
Preparerefresh ();
1.
Initialize any placeholder property sources in the context environment
Preprocessing configuration, currently seen in Web tier implementations (preprocessing Web configuration)
Initpropertysources ();

2.//Validate that all properties marked as required is resolvable
See Configurablepropertyresolver#setrequiredproperties
Verifying system Configuration
Getenvironment (). Validaterequiredproperties ();

Tell the subclass to refresh the internal bean factory.
Configurablelistablebeanfactory beanfactory = Obtainfreshbeanfactory ();

Prepare The Bean factory for use with this context.
Pretreatment beanfactory
Preparebeanfactory (beanfactory);


try {
Allows post-processing of the Bean factory in context subclasses.
Preprocessing beanfactory post-processing now also sees only Web implementations (registration dependent dependencies)
Postprocessbeanfactory (beanfactory);

Invoke factory processors registered as beans in the context.
Performing beanfactory post-processing
Invokebeanfactorypostprocessors (beanfactory);
Process priority (the instance itself is not considered)
1.BeanDefinitionRegistryPostProcessor
2.BeanFactoryPostProcessor
3.BeanFactoryPostProcessor (plug-in processing) priorityordered-ordered->nonordered

Register Bean processors that intercept bean creation.
Register post processor (Scan interface Beanpostprocessor)
Registerbeanpostprocessors (beanfactory);
Executive priority Priorityordered, ordered-nonordered

Initialize message source for this context.
Initializing Internationalized objects
Initmessagesource ();

Initialize Event Multicaster for this context.
Initialize Event broadcast Object
Initapplicationeventmulticaster ();

Initialize other special beans in specific context subclasses.
After finishing the process, refresh now only sees the web and defaultlifecycleprocessor implementation
Onrefresh ();

Check for listener beans and register them.
Scan all Spring event interface objects by registering processing spring event priority itself instance events
Registerlisteners ();

Instantiate all remaining (Non-lazy-init) singletons.
Initialize Complete Beanfactory processor
Finishbeanfactoryinitialization (beanfactory);

Last Step:publish corresponding event.
Complete beanfactory container Handling
Finishrefresh ();
1.initLifecycleProcessor ();//Initialize life cycle processor
2.getLifecycleProcessor (). Onrefresh ();//Refresh Life cycle processor
3.publishEvent (New Contextrefreshedevent (this)); Publish Contextrefreshedevent Events
4.registerApplicationContext ();//Registration context


Closing container Events
1.runtime.getruntime (). Removeshutdownhook (This.shutdownhook); Mobile JVM thread-level monitoring
2.livebeansview.unregisterapplicationcontext (this);//Clear Context Unregistermbean
3.publishEvent (New Contextclosedevent (this)); Publish Shutdown events
4.getLifecycleProcessor (). OnClose ();
5.destroyBeans ()//do not see the implementation
6.closeBeanFactory ();//Delete Bean
7.//let subclasses do some final clean-up if they wish ...
OnClose ()


Summary:
1. Pre-treatment injection related dependency implementation Beanfactorypostprocessor
2. Modify the bean implementation after preprocessing Beanpostprocessor
3. Implement Defaultlifecycleprocessor after preprocessing is completed

4. Implement the Applicationlistener Contextrefreshedevent event after completing the entire load

5. Close and implement Defaultlifecycleprocessor or Applicationlistener contextclosedevent events prior to destruction


Factorybean,abstractfactorybean<t>, Initializingbean, Disposablebean,beanfactoryaware

Spring START process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.