Spring 引导:单独的 WS 和 MVC 请求处理

Spring Boot: separate WS and MVC requests handling

有一个 Spring 结合了 WS 和 MVC 的引导应用程序。我的问题是如何将 WS 请求和 MVC 请求路由到不同的调度程序 servlet。这是一个代码片段:

(不工作):

@Configuration
public class WebServicesConfiguration extends WsConfigurerAdapter implements WebApplicationInitializer {

    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext context) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(context);
        servlet.setTransformWsdlLocations(true);

        return new ServletRegistrationBean(servlet, "/*");
    }

    @Bean
    public SimpleUrlHandlerMapping simpleUrlHandlerMapping() {
        SimpleUrlHandlerMapping handler = new SimpleUrlHandlerMapping();
        handler.setDefaultHandler("mvc");

        return handler;
    }

    @Override
    public void onStartup(ServletContext servletContext) {
        DispatcherServlet ds = new DispatcherServlet(new GenericWebApplicationContext());
        ServletRegistration.Dynamic appServlet = servletContext.addServlet("mvc", ds);
        appServlet.addMapping("/dummy");
    }
}

WS 使用 '/*' 映射。此示例中的 MVC 使用 '/dummy' 映射。问题是 MVC 请求转到 WS 调度程序 servlet。我尝试使用 SimpleUrlHandlerMapping 将 MVC 请求路由到 MVC 调度程序 servlet,但它没有帮助。不允许更改 WS 的映射。

P.S。上面有错误。 WS映射是'/'

已找到解决方案。我在引导 class' 注释中添加了以下排除项

@SpringBootApplication(exclude = DispatcherServletAutoConfiguration.class)

并按以下方式更改了 WebServicesConfiguration class:

@Configuration
public class WebServicesConfiguration extends WsConfigurerAdapter {

    @Bean
    public ServletRegistrationBean mvcDispatcherServlet(ApplicationContext context) {
        DispatcherServlet servlet = new DispatcherServlet();
        servlet.setApplicationContext(context);

        return new ServletRegistrationBean(servlet, "/dummy");
    }

    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext context) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(context);
        servlet.setTransformWsdlLocations(true);

        return new ServletRegistrationBean(servlet, "/");
    }
}