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