Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot SOAP webservice with MVC

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

  • https://spring.io/guides/gs/serving-web-content/
  • https://spring.io/guides/gs/producing-web-service/

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!

like image 345
jareks Avatar asked Jan 12 '15 15:01

jareks


People also ask

Does spring boot support SOAP?

This guide will help you create a SOAP Web Service with Spring Boot Starter Web Services. We will take a Contract First approach by definining an XSD and exposing a WSDL from it.

How do you call a SOAP web service from REST API in spring boot?

Steps to Consume a SOAP service :Create spring boot project and Get the WSDL from the provider . Convert the WSDL to Stub. Understand the request ,response and the types ,operations using any tool like SOAP UI. Form the request object by mapping data and call the soap uri with marshal the java objects as XML.

How do I host a SOAP web service?

Enter http://www.webservicex.net/periodictable.asmx for “URL to the SOAP web service endpoint” prompt. Enter http://www.webservicex.net/periodictable.asmx?WSDL for “HTTP URL or local fie system path to WSDL file” prompt. Enter “y” to Expose operations as REST APIs. Leave blank to “Maps WSDL binding operations to Node.


1 Answers

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/*");
}
like image 122
M. Deinum Avatar answered Oct 05 '22 18:10

M. Deinum