简体   繁体   中英

Force load of web.xml before Spring WebApplicationInitializer classes

How can I be sure that web.xml in a web application is loaded before any Spring WebApplicationInitializer classes?

From the Javadoc of WebApplicationInitializer :

WEB-INF/web.xml and WebApplicationInitializer use are not mutually exclusive; for example, web.xml can register one servlet, and a WebApplicationInitializer can register another. An initializer can even modify registrations performed in web.xml through methods such as ServletContext.getServletRegistration(String)...

So according to this I might assume that web.xml is loaded before any WebApplicationInitializer classes. This I have not observed to be the case.

I am providing an implementation of WebApplicationInitializer and what I want to do in the code is the following so that if a servlet has already been registered in a web.xml file then I do not attempt to register it for a second time:

@Override
public void onStartup(ServletContext servletContext) {

    if(servletContext.getServletRegistration(MY_SERVLET_NAME) == null) {
        // Servlet not already registered in web.xml so register it now
        servletContext.addServlet(..etc)
    }
}

My mistake. My if check was erroneous leading me to think that web.xml was loaded after. For reference I'll leave the question but the ordering does seem to be web.xml first followed by any WebApplicationInitializer classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM