How to Create REST and SOAP Services In Same Spring Boot Application?
Here, I will not tell you how to write SOAP and REST services. The only thing I will mention is how you open SOAP and REST services together in a single application.
For example, suppose you have a REST service such as the code example below.
@RestController@RequestMapping("restservice/google")
public class GoogleController {
....@PostMapping(value = "/advertisementOperations")
@ResponseBody
public ResponseDTO advertisementOperations(@RequestBody RequestDTO requestDTO)}
Here, the path you will use for REST services should be root_path/restservice/your_rest_services_set_path
There is another example below;
@RestController@RequestMapping("restservice/yahoo")
public class YahooController {
....@PostMapping(value = "/salaryOperations")
@ResponseBody
public ResponseDTO salaryOperations(@RequestBody RequestDTO requestDTO)}
Now, let’s see how the definition is made for using SOAP services together with REST services in the same application.
@EnableWs
@Configuration
public class SoapWebServiceConfig extends WsConfigurerAdapter {@Bean
public ServletRegistrationBean messageDispatcherServlet(ApplicationContext applicationContext) {
MessageDispatcherServlet servlet = new MessageDispatcherServlet();
servlet.setApplicationContext(applicationContext);
servlet.setTransformWsdlLocations(true);
return new ServletRegistrationBean(servlet, "/soapservice/*");
}
.....
}
As seen above, it is necessary to define different paths for SOAP and REST.
From the link below, you can see the full creation of SOAP services …