Specify a custom web.xml to an embedded tomcat

后端 未结 1 1587
半阙折子戏
半阙折子戏 2020-12-05 16:09

Is there a way to specify a different web.xml from the standard WEB-INF/web.xml when using an embedded tomcat instance?

I would like to put

相关标签:
1条回答
  • 2020-12-05 16:33

    I was stuck with a similar problem and the solution for using an alternative web.xml is simpler than one would dare to think:

    2 lines:

    Context webContext = tomcat.addWebapp("/yourContextPath", "/web/app/docroot/");
    webContext.getServletContext().setAttribute(Globals.ALT_DD_ATTR, "/path/to/custom/web.xml");
    

    Voila! The magic happens in org.apache.catalina.startup.ContextConfig#getWebXmlSource

    Disclaimer: Tested on Tomcat 7.0.42

    0 讨论(0)
提交回复
热议问题