You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot配置SOAP WS-Security遇Bean创建失败及类缺失问题求助

解决Spring WS Security的XWSSecurityException类找不到问题

你遇到的是典型的依赖缺失问题:spring-ws-security需要依赖XWS Security库来实现SOAP请求的签名/验证逻辑,但你的项目里没有引入这个核心库,所以运行时抛出了NoClassDefFoundError。

问题根源

XwsSecurityInterceptor是Spring WS基于XWS Security实现的安全拦截器,它依赖com.sun.xml.wss包下的类,但这个包并不包含在spring-ws-security依赖中,必须单独引入才能正常工作。

解决方案

1. 优化spring-ws-security依赖版本(推荐)

你当前手动指定了spring-ws-security的版本为2.2.0.RELEASE,但你的Spring Boot parent是2.1.9.RELEASE,Spring Boot已经为Spring WS组件维护了兼容的版本集,建议移除手动版本号,避免版本冲突:

<dependency>
    <groupId>org.springframework.ws</groupId>
    <artifactId>spring-ws-security</artifactId>
    <!-- 移除手动指定的version,由Spring Boot parent自动管理兼容版本 -->
</dependency>

2. 添加XWS Security核心依赖

在pom.xml的<dependencies>块中添加以下依赖,这个包包含了缺失的XWSSecurityException类:

<dependency>
    <groupId>com.sun.xml.ws</groupId>
    <artifactId>xws-security</artifactId>
    <version>3.0.2</version>
    <!-- 注:若遇到兼容问题,可尝试匹配Spring WS版本的xws-security,Spring Boot 2.1.x系列对应3.0.x版本即可 -->
</dependency>

3. Java 9+ 额外适配(针对你的Java 11环境)

如果你后续遇到模块访问权限问题,可以在spring-boot-maven-plugin中添加JVM参数,放宽模块访问限制:

<plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <configuration>
        <jvmArguments>
            --add-modules java.xml.bind,java.xml.ws.annotation
            --add-exports java.base/jdk.internal.misc=ALL-UNNAMED
        </jvmArguments>
    </configuration>
</plugin>

完成以上修改后,执行mvn clean install重新构建项目,应该就能解决类找不到的问题了。

内容的提问来源于stack exchange,提问作者Miha Zoubek

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:13:14