java.lang.NoClassDefFoundError:org / apache / cxf / jaxrs / model / doc / DocumentationProvider

时间:2018-04-30 10:09:37

标签: spring cxf swagger

我正在尝试整合招摇。我按照here给出的步骤。应用程序上下文和pom.xml配置相同。 当重启tomcat时出现此错误。

2018-04-30 14:01:33 ERROR ContextLoader:351 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'productAPIServer': Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/apache/cxf/jaxrs/model/doc/DocumentationProvider
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1583)

我已经包含了

 <dependency>
 <groupId>org.apache.cxf</groupId>
 <artifactId>cxf-rt-rs-service-description-swagger</artifactId>
 <version>3.1.7</version>
 </dependency>
 <dependency>
 <groupId>org.apache.cxf</groupId>
 <artifactId>cxf-rt-rs-service-description</artifactId>
 <version>3.1.7</version>
 </dependency>
 <dependency>
 <groupId>org.apache.cxf</groupId>
 <artifactId>cxf-core</artifactId>
 <version>3.1.7</version>
 </dependency>

上下文xml文件中的更改:

<bean id="jacksonJsonProviderFasterxml" class="com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider" />
<bean id="swagger2Feature"   class="org.apache.cxf.jaxrs.swagger.Swagger2Feature">

<property name="basePath" value="/staticdata-web-service"/>
<property name="license" value=""/>
<property name="licenseUrl" value=""/>
<property name="title" value="Static data web service"/>
</bean>

添加功能

<jaxrs:features>
<ref bean="swagger2Feature" />
</jaxrs:features>

2 个答案:

答案 0 :(得分:0)

您的版本不匹配。当您在Maven上搜索该类时,您会发现DocumentationProvider的包已从版本3.0.x更改为3.1.x

  

组织/阿帕奇/ CXF / JAXRS /模型/ DOC / DocumentationProvider

  

组织/阿帕奇/ CXF / JAXRS /模型/ WADL / DocumentationProvider

如果不了解整个构建和程序包依赖关系,很难分辨出不匹配的位置。但你可能想要运行

 mvn dependency:tree -Dverbose

在您的项目文件夹中,查看哪些软件包版本会引发问题,以便提升您的ClassNotFoundException

答案 1 :(得分:0)

在您的 Maven 项目中使用以下依赖项来解决您的问题,

    <!-- https://mvnrepository.com/artifact/org.apache.cxf/cxf-rt-rs-json-basic -->
    <dependency>
        <groupId>org.apache.cxf</groupId>
        <artifactId>cxf-rt-rs-json-basic</artifactId>
        <version>3.4.3</version>
        <scope>provided</scope>
    </dependency>