These days to see the source of Tomcat, a lot of questions, such as one of the "Tomcat How to load Web. xml", the following is the process of tracking, where the event listener has an observer pattern, better. Recorded for reference
1>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>tomcat Load web.xml>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>2 3 4 5Tomcat loads the user's servlet into the context in Web. XML and instantiates the servlet to/web-inf/classes/in6 The process is generally as follows7 8 The action to load the Web. XML is triggered only when the message received by the event receiver is configure_start_event.9 Ten /** One * The lifecycleevent type for the "Configure_start" event. Used by those A * Components of Use a separate component to perform configuration and - * need to signal when configuration should is performed-usually after - * {@link#BEFORE_START_EVENT} and before {@link#START_EVENT}. the */ - Public Static FinalString configure_start_event = "Configure_start"; - - so who's going to register the message in the listener? As below, look for it from the startup process: + - + Org.apache.catalina.startup.Bootstrap.start () A-Org.apache.catalina.startup.Catalina.start () at----"Load () -------" - getserver (). Init (); -server=== "Org.apache.catalina.core.StandardServer" ------"standardserver.initinternal () - standardserver.startinternal () in---" - voidjava.org.apache.catalina.util.LifecycleBase.fireLifecycleEvent (String type, Object data) to +Firelifecycleevent (Configure_start_event,NULL); ----" theLifecyclesupport firelifecycleevent (Configure_start_event,NULL); * $ broadcast by Lifecyclesupport to all the receivers,Panax Notoginseng the receiver determines whether it needs to handle "Observer mode here" as needed - the + Aand publicclassContextconfigImplementsLifecyclelistener the is the so-called recipient + in its overridden lifecycleevent (Lifecycleevent event) method - $ if(Event.gettype (). Equals (Lifecycle.configure_start_event)) { $ - Configurestart (); This method is the specific method for loading - the - protected synchronized voidConfigurestart ()Wuyi-----------------"Webconfig () the : :::: - Wu webconfig () in - { AboutString resource = $"/web-inf/classes/" +binding.getname (); - Try { -URL url =Scontext.getresource (Resource); - processannotationsurl (URL, webxml, A Webxml.ismetadatacomplete ()); +}Catch(malformedurlexception e) { the Log.error (sm.getstring ( -"Contextconfig.webinfclassesurl", $ Resource), e); the } the the } the ----------------" in voidJava.org.apache.catalina.startup.ContextConfig.processAnnotationsUrl (URL url, webxml fragment,Booleanhandlestypesonly) the----------" the voidJava.org.apache.catalina.startup.ContextConfig.processAnnotationsJndi (URL url, webxml fragment,Booleanhandlestypesonly) About------------" the voidJava.org.apache.catalina.startup.ContextConfig.processAnnotationsStream (InputStream is, webxml fragment,BooleanHANDLESTYPESONLY)throwsclassformatexception, IOException the--------------" the voidJava.org.apache.catalina.startup.ContextConfig.processAnnotationWebServlet (String className, Annotationentry AE, webxml fragment) + ----------" the Fragment.addservlet (servletdef);Bayi fragment.addservletmapping (Urlpattern, servletname); the the -------->Webxml.configurecontext (context); - the Public voidConfigurecontext (Context context) { theWrapper Wrapper =Context.createwrapper (); the Context.addchild (wrapper); the context.addservletmapping (Entry.getkey (), Entry.getvalue ()); - the>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>tomcat Load web.xml>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>> the the
Tomcat loading web. xml