Spring JavaConfig: Add mapping for custom Servlet

后端 未结 1 1728
感情败类
感情败类 2021-01-05 06:37

In a javaconfig-based Spring 4.0 project, how can I add a mapping for a certain URL to a Servlet other than the Spring DispatcherServlet.

Im my case I want to use h2

1条回答
  •  悲&欢浪女
    2021-01-05 07:03

    The easiest way is to use initializer implementing directly WebApplicationInitializer and the add into onStartup(ServletContext servletContext) method following code;

    ServletRegistration.Dynamic h2Servlet = servletContext.addServlet("h2Servlet", new org.h2.server.web.WebServlet());
    h2Servlet.setLoadOnStartup(1);
    h2Servlet.addMapping("/h2/*");
    

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