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/*
- webservicelocalhost:8080/web/*
- MVC componentsThanks in advance!
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.
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.
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.
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/*");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With