I am attempting to get CXF and Sprint Boot to play nicely. I have a JAX-WS service endpoint called SubscriberApi. Looking at the spring-boot logs I see successful mapping:
Mapping servlet: 'CXFServlet' to [/api/*]
Setting the server's publish address to be /SubscriberApi
However, I cant seem to get the WSDL when hitting:
http://localhost:8080/api/SubscriberApi?wsdl
@Configuration
@ImportResource({"classpath:META-INF/cxf/cxf.xml"})
public class CxfConfiguration {
@Bean
public SubscriberApi subscriberApi() {
return new SubscriberApi();
}
@Bean
public ServletRegistrationBean servletRegistrationBean() {
CXFServlet cxfServlet = new CXFServlet();
ServletRegistrationBean servletRegistrationBean =
new ServletRegistrationBean(cxfServlet, "/api/*");
servletRegistrationBean.setLoadOnStartup(1);
return servletRegistrationBean;
}
@DependsOn("servletRegistrationBean")
@Bean
public Endpoint jaxwsEndpoint(SubscriberApi subscriberApi){
javax.xml.ws.Endpoint jaxwsEndpoint =
javax.xml.ws.Endpoint.publish("/SubscriberApi", subscriberApi);
return jaxwsEndpoint;
}
}
You can now use autoconfiguration with a Spring Boot CXF starter by adding:
See also: http://cxf.apache.org/docs/springboot.html
Have your
jaxwsEndpoint
bean return an instance oforg.apache.cxf.jaxws.EndpointImpl
, which extendsjavax.xml.ws.Endpoint
:The original post doesn't include a runnable example, but this should solve the issue.
A running example can be found here, with all the configuration linked together: Application.java
There's a much easier way to get Spring Boot & Apache CXF running and providing a SOAP webservice based on your WSDL file: Just use the cxf-spring-boot-starter, which does everything for you. You only need to use the starter and it's companion Maven plugin in your
pom.xml
like this (full example!):Place your wsdl somewhere inside
src/main/resources
, implement your endpoint class and your done!. That's really everything, no manual boilerplate coding (noServletRegistrationBean
etc.). This is just generated for you based on the WSDL - 100% contract first.Here's also a fully comprehensible example project: https://github.com/codecentric/spring-samples/tree/master/cxf-boot-simple. And there's also a blog post series, which will introduce you to everything related to know: https://blog.codecentric.de/en/2016/10/spring-boot-apache-cxf-spring-boot-starter/ Have fun!