Good day,
I am using apache cxf and spring boot to build a web service but when I try to call the endpoint, it gives me this error:
WARN 15936 --- [nio-8080-exec-4] o.a.cxf.phase.PhaseInterceptorChain : Application {
endpointMethod has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: org/apache/cxf/jaxb/JAXBToStringStyle
[...]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_144]
Caused by: java.lang.NoClassDefFoundError: org/apache/cxf/jaxb/JAXBToStringStyle
Here is my configuration for the webservice:
@Configuration
public class WebServiceConfig {
@Bean
public org.springframework.boot.web.servlet.ServletRegistrationBean cxfServlet() {
return new org.springframework.boot.web.servlet.ServletRegistrationBean(new CXFServlet(), "/cxf-api/*");
}
@Bean(name = Bus.DEFAULT_BUS_ID)
public SpringBus springBus() {
return new SpringBus();
}
@Bean
public Conc2MGPService conc2MGPService() {
return new RegistrationServiceEndpoint();
}
@Bean
public Endpoint endpoint() {
EndpointImpl endpoint = new EndpointImpl(springBus(), concessionario2MGPService());
endpoint.publish("/registration_endpoint");
return endpoint;
}
and here my POM:
<project ...">
<groupId>com.me.justin</groupId>
<artifactId>registration-gateway-app</artifactId>
<packaging>war</packaging>
<name>registration-gateway-app</name>
<description>Demo project for Spring Boot</description>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jersey</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-spring-boot-starter-jaxws</artifactId>
</dependency>
<dependency>
<groupId>it.justin</groupId>
<artifactId>justin-soap-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-databinding-jaxb</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
What am I missing? What I am doing here is a simple log on the object passed on the request.
@Override
public RegisterContract(RegisterContractRequest registerContractRequest) {
log.info("RegisterContract" + registerContractRequest);
return null;
}
I think that something is missing in my POM but I can't figure out what.
Add this dependency to your pom.
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-bundle</artifactId>
<version>2.7.18</version>
</dependency>
As a side note this jar is deprecated, try to update your dependencies. New version of the above jar is like below. ( But in order to use it, you have update your related dependencies)
<groupId>org.apache.cxf.xjc-utils</groupId>
<artifactId>cxf-xjc-runtime</artifactId>
<version>3.2.1</version>