解决JDK11 NoClassDefFoundError: Could not initialize class org.apache.cxf.attachment.AttachmentUtil

在parent.pom声明并排除依赖

<DependencyManagement>
...省略

<cxf-jaxws-starter.version>3.4.5</cxf-jaxws-starter.version>
<javax.activation.version>1.1</javax.activation.version>


<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
    <version>${cxf-jaxws-starter.version}</version>
    <exclusions>
        <exclusion>
            <groupId>com.fasterxml.woodstox</groupId>
            <artifactId>woodstox-core</artifactId>
        </exclusion>
        <exclusion>
            <groupId>com.sun.activation</groupId>
            <artifactId>jakarta.activation</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>javax.xml.ws</groupId>
    <artifactId>jaxws-api</artifactId>
    <version>${javax-jaxws.version}</version>
    <exclusions>
        <exclusion>
            <groupId>javax.annotation</groupId>
            <artifactId>javax.annotation-api</artifactId>
        </exclusion>
    </exclusions>
</dependency>

<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
    <version>${javax.activation.version}</version>
</dependency>

</DependencyManagement>

应用层pom.xml

<dependency>
    <groupId>org.apache.cxf</groupId>
    <artifactId>cxf-spring-boot-starter-jaxws</artifactId>
</dependency>
<dependency>
    <groupId>javax.xml.ws</groupId>
    <artifactId>jaxws-api</artifactId>
</dependency>
<dependency>
    <groupId>javax.activation</groupId>
    <artifactId>activation</artifactId>
</dependency>

注: 

 <exclusion>
            <groupId>com.fasterxml.woodstox</groupId>
            <artifactId>woodstox-core</artifactId>
     </exclusion>

是为了避免和Jackson自带的冲突

如要兼容jaxb的注解

parent.pom声明


<!--jackson 不得在项目中指定-->
<jackson-bom.version>2.15.4</jackson-bom.version>

<dependency>
    <groupId>com.fasterxml.jackson</groupId>
    <artifactId>jackson-bom</artifactId>
    <version>${jackson-bom.version}</version>
    <type>pom</type>
    <scope>import</scope>
</dependency>

将这段配置放在需要的地方,或在父级项目中集成一个POM依赖以便使用XmlMapper进行XML解析和生成。

<!--jackson xml、json -->
<dependency>
    <groupId>com.fasterxml.jackson.dataformat</groupId>
    <artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<!--for JaxbAnnotationModule -->
<dependency>
    <groupId>com.fasterxml.jackson.module</groupId>
    <artifactId>jackson-module-jaxb-annotations</artifactId>
</dependency>


大功告成!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值