I was having some problem trying to load different web.xml for my Spring MVC project. I have 2 web.xml, one for development and the other for production. Each of the web.xml will load up different filters respectively.
I have this class, upon initialization, the project will execute this class to set the properties:
public class StartupServlet extends HttpServlet { private final String SYSTEM_URL = "SystemURL"; private Logger log = LogManager.getLogger(StartupServlet.class); public void destroy() { } public void init() throws ServletException { try { Logger log = LogManager.getLogger(StartupServlet.class); ServletConfig config = getServletConfig(); String url = (String) config.getInitParameter(SYSTEM_URL); Constants.FULLPATHWITHCONTEXT = url; if (!Constants.CUR_ENV.equals(Constants.CUR_ENV_PROD)) { XmlWebApplicationContext context = new XmlWebApplicationContext(); context.setConfigLocation("/WEB-INF/web_prod.xml"); } else { XmlWebApplicationContext context = new XmlWebApplicationContext(); context.setConfigLocation("/WEB-INF/web.xml"); } Constants.SERVLET_CONTEXT = this.getServletContext(); } catch (Exception e) { } } }
I am trying to set it to load different web.xml according to the value I set for CUR_ENV in Constants.java. However, it just keep loaded up the web.xml regardless if I set the CUR_ENV to CUR_ENV_PROD.
Any ideas on how to do this? Thanks!
https://stackoverflow.com/questions/66848637/spring-mvc-loads-different-web-xml-accordingly March 29, 2021 at 12:07PM
没有评论:
发表评论