membersound
membersound

Reputation: 86627

How to use CXF soap servlet aside spring REST servlet?

I'm providing a soap webservice with java-first approach, thus using CXF for this. To make it publishing with spring-boot, I have the following dispatcher servlet:

@Bean
public ServletRegistrationBean dispatcherServletRegistration() {
    ServletRegistrationBean registration = new ServletRegistrationBean(new CXFServlet(), "/services/*");
    registration.setName(DispatcherServletAutoConfiguration.DEFAULT_DISPATCHER_SERVLET_REGISTRATION_BEAN_NAME);
    return registration;
}

This works fine, but I now want to offer a REST service aside. The rest service should NOT be published by cxf, but by the default spring mapping:

@RestConstroller
@RequestMapping("/rest/content")
public class MyServiceRest extends SpringBeanAutowiringSupport {

}

The result of this:

So, somehow the latter is inside the context of the CXFServlet, and the REST service is not found.

What do I have to change to make this setup work?

By the way: when I remove the ServletRegistrationBean, the rest service works as expected. But that's not an option as I have to offer the soap service alongside.

Upvotes: 1

Views: 1620

Answers (1)

Andy Wilkinson
Andy Wilkinson

Reputation: 116031

Your bean named dispatcherServletRegistration is replacing Spring Boot's default DispatcherServlet so your left with just a CXFServlet and no DispatcherServlet in your application.

Update your bean to register the CXFServlet to something like this:

@Bean
public ServletRegistrationBean cxfServletRegistration() {
     return new ServletRegistrationBean(new CXFServlet(), "/services/*");
}

Upvotes: 2

Related Questions