Tag: Color description operation Cat ring is larger than the link parameter file
1. Background
In large environments where the convention is larger than the configuration, the XML configuration file is increasingly superseded by the 0 configuration. Most of the configuration in the original XML is also defined in the Java class.
Instead, Webapplicationinitializer can be seen as a substitute for Web. XML, which loads the implementation class when it is launched, and implements the operation of the servlet, filter, listener in the implementation class.
2. Source Code Analysis
First look at the Webapplicationinitializer interface definition, you can see that there is only one interface, parameter ServletContext explained to be used to initialize;
Again, see the annotations on the class, the hint can refer to springservletcontainerinitializer.
turn to see Springservletcontainerinitializer, first look at class definition;
First, the class implements the Servletcontainerinitialize interface, and it is explicitly stated in the comments that the implementation class is loaded when the container starts.
Then look at the rewritten method Onstartup (set<class<?>> webappinitializerclasses, ServletContext ServletContext)
webappinitializerclasses, which is interpreted as the implementation class for all Webapplicationinitializer interfaces, that is, when the container starts, The implementation class type of webappinitializerclasses is passed as a parameter;
The following code is easy to read, if it is not the interface, put the implementation of the class instantiation to LinkedList, and then loop through the implementation of the method overridden in the class to achieve the role of XML instead.
3. Application
After analyzing the source code, the application of the actual project.
Nothing to say, write the servlet, filter, listener operation.
"Spring Framework"? Webapplicationinitializer Source code Analysis and application