![](/img/trans.png)
[英]Getting NoClassDefFoundError for com.sun.xml.wss.XWSSecurityException
[英]java.lang.ClassNotFoundException: com.sun.xml.wss.XWSSecurityException
我有一个现有的基于SOAP的Web服务,并且尝试在其上使用“ XwsSecurityInterceptor”和“ SpringDigestPasswordValidationCallbackHandler”来实现Spring Web服务安全性。 这就是我的弹簧配置的样子。
我正在JBoss7.1 AS中部署此应用程序。在应用程序启动时,引发了以下异常。它抱怨未找到“ com.sun.xml.wss.XWSSecurityException”。
org.springframework.beans.factory.BeanCreationException:创建名称为“ org.springframework.ws.soap.addressing.server.AnnotationActionEndpointMapping#0”的bean时出错:初始化init方法失败; 嵌套的异常是java.lang.NoClassDefFoundError:com / sun / xml / wss / XWSSecurityException原因:java.lang.ClassNotFoundException:com.sun.xml.wss.XWSSecurityException
现在,我试图了解该问题的根本原因。 因此,我从POM文件开始。
以下依赖性在pom中。
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-core</artifactId>
<version>${org.springframework.ws.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-security</artifactId>
<version>${org.springframework.ws.version}</version>
</dependency>
<dependency>
<groupId>com.sun.xml.wss</groupId>
<artifactId>xws-security</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>xmldsig</artifactId>
<version>1.0</version>
</dependency>
作为研发的一部分,我使用了“ spring-ws-core”和“ spring-ws-security”的较旧版本(2.1.2),以及“ sjsxp”的“ 1.0.2”版本。 应用程序启动,并且输入无效密码后出现身份验证错误。 如果我提供正确的凭据,应用程序会很好地响应。 这就是我要使用这些Jars的最新版本实现的目标。
现在,我想知道为什么2.3.0 / 2.4.0中缺少内容。
所以我尝试了'mvndependency:tree -Dverbose',发现2.1.2版本带来了'xws-security'。
因此,我想到了添加这种依赖性。
<dependency>
<groupId>com.sun.xml.wss</groupId>
<artifactId>xws-security</artifactId>
<version>3.0</version>
</dependency>
现在,这迫使我再添加两个依赖项。 我也添加了这些。
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>javax.xml</groupId>
<artifactId>xmldsig</artifactId>
<version>1.0</version>
</dependency>
但是第二个'xmldsig'在Maven存储库中丢失了。 我可以下载并将其手动添加到我的本地M2存储库中。 但是我想以适当的方式修复它。 在搜索时,我遇到了这个线程。 http://maven.40175.n5.nabble.com/where-to-get-xmldsig-1-0-jar-td92435.html
有人在谈论替代方案。
而且我可以看到它在2.3.0版本的“ spring-ws-security:jar”中可用。
现在我的问题是,需要避免/添加什么,以便应用程序使用最新版本的jars启动? 手指交叉...
有时您需要成为软件考古学家才能调试这些东西。
查看spring-ws-security:2.4.0.RELEASE的pom,您会发现xws-security:3.0
依赖项是可选的(以及其他)。 您将需要阅读spring-ws-security文档,以确定应该包括哪些optional
依赖项。
假设您已确定需要xws-security
模块,则需要查看它的pom ,这是考古学发挥作用的地方。 该模块的历史可以追溯到2008年,那时仍支持Java 5。 Java 6(和/或Java EE)及更高版本支持此工件的依赖项列表中的所有API。 将它们中的任何一个包含在您的构建或部署工件中都是痛苦的秘诀。
因此,您应该排除它们:
<dependency>
<groupId>com.sun.xml.wss</groupId>
<artifactId>xws-security</artifactId>
<version>3.0</version>
<exclusions>
<exclusion>
<!-- Part of JDK -->
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
</exclusion>
<exclusion>
<!-- Part of Java EE -->
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<!-- Part of JDK -->
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</exclusion>
<exclusion>
<!-- Part of JDK -->
<groupId>javax.xml.stream</groupId>
<artifactId>stax-api</artifactId>
</exclusion>
<exclusion>
<!-- Part of JDK -->
<groupId>javax.xml.crypto</groupId>
<artifactId>xmldsig</artifactId>
</exclusion>
<exclusion>
<!-- Part of JDK -->
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
</exclusion>
</exclusions>
</dependency>
尝试使用spring-ws-security:2.4.0.RELEASE
和spring version 4.3.3.RELEASE
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.