【问题标题】:NoClassDefFoundError on org/apache/cxf/jaxb/JAXBToStringStyleorg/apache/cxf/jaxb/JAXBToStringStyle 上的 NoClassDefFoundError
【发布时间】:2018-02-14 13:53:16
【问题描述】:

早安,

我正在使用 apache cxf 和 spring boot 来构建 Web 服务,但是当我尝试调用端点时,它给了我这个错误:

    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

这是我对网络服务的配置:

@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;
}

这里是我的 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>

我错过了什么? 我在这里所做的是对请求传递的对象的简单日志。

@Override
    public RegisterContract(RegisterContractRequest registerContractRequest) {
        log.info("RegisterContract" + registerContractRequest);
        return null;
    }

我认为我的 POM 中缺少某些东西,但我不知道是什么。

【问题讨论】:

  • 您将依赖项定义为运行时,例如它将由容器在运行时提供。如果您使用的是嵌入式容器,或者它不是您部署到的容器的一部分,则需要编译该依赖项。

标签: java maven spring-boot cxf jax-ws


【解决方案1】:

将此依赖项添加到您的 pom.xml 中。

 <dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-bundle</artifactId>
    <version>2.7.18</version>
</dependency>

作为旁注,此 jar 已弃用,请尝试更新您的依赖项。上述 jar 的新版本如下所示。 (但为了使用它,您已经更新了相关依赖项)

<groupId>org.apache.cxf.xjc-utils</groupId>
<artifactId>cxf-xjc-runtime</artifactId>
<version>3.2.1</version>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-07-27
    • 1970-01-01
    • 1970-01-01
    • 2015-11-23
    • 2016-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多