Search code examples
javaspringspring-mvcspring-bootspring-ws

Spring Boot SOAP webservice with MVC


I would like to combine two Spring (spring-boot) applications from Spring guides:

Unfortunately, these examples do not work together. There is a problem with servlet dispatcher. After adding dispatcherServlet bean - MVC servlet is not working (Error 404).

@Bean
public ServletRegistrationBean dispatcherServlet(ApplicationContext applicationContext) {
    MessageDispatcherServlet servlet = new MessageDispatcherServlet();
    servlet.setApplicationContext(applicationContext);
    servlet.setTransformWsdlLocations(true);
    return new ServletRegistrationBean(servlet, "/ws/*");
}

How to configure servlet dispatcher to work properly?

I would like to have:

  • localhost:8080/ws/* - webservice
  • localhost:8080/web/* - MVC components

Thanks in advance!


Solution

  • The problem lies in the registration of the MessageDispatcherServlet due to the name dispatcherServlet it overrides the by Spring Boot registered DispatcherServlet. The latter is needed for the MVC part of your website.

    To fix it just rename your method to anything but dispatcherServlet say messageDispatcherServlet.

    @Bean
    public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
        MessageDispatcherServlet servlet = new MessageDispatcherServlet();
        servlet.setApplicationContext(applicationContext);
        servlet.setTransformWsdlLocations(true);
        return new ServletRegistrationBean(servlet, "/ws/*");
    }