Eclipse抱怨说,当我尝试在Spring Boot配置中连接它时,它无法找到Wss4jSecurityInterceptor(它无法导入):
@Bean public Wss4jSecurityInterceptor wss4jSecurityInterceptor(){...}
这里是pom.xml文件的相关摘录:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.abc</groupId>
<artifactId>abc-connectivity-boot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>abc-connectivity-boot</name>
<description>FFM Connectivity via Digested UserNameToken</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-ws</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-test</artifactId>
<version>2.2.1.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<!-- <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-log4j</artifactId>
</dependency> -->
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
我错过了什么?
提前谢谢你。 西麦
将 spring-ws-security 依赖项添加到pom.xml中(根据M. Deinum的建议)我现在看到以下运行时错误:
Caused by: java.lang.NoClassDefFoundError: org/apache/ws/security/WSSecurityException
at connect.ConnectivityTestingConfig.wss4jSecurityInterceptor(ConnectivityTestingConfig.java:68)
at connect.ConnectivityTestingConfig$$EnhancerBySpringCGLIB$$e29e9046.CGLIB$wss4jSecurityInterceptor$4(<generated>)
at connect.ConnectivityTestingConfig$$EnhancerBySpringCGLIB$$e29e9046$$FastClassBySpringCGLIB$$bb38be14.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:309)
at connect.ConnectivityTestingConfig$$EnhancerBySpringCGLIB$$e29e9046.wss4jSecurityInterceptor(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162)
添加以下依赖项:
<dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>1.5.8</version>
</dependency>
似乎解决了上述错误,但这是朝着正确的方向发展吗? 顾虑:
通过上述补充,pom.xml中是否应该 spring-boot-starter-security ?
如何控制添加的 wss4j 的版本?例如,wss4j-1.5.8.jar似乎不兼容,而wss4j-1.6.18似乎有效。如何将Spring Boot的版本与其所需的依赖关系相关联?
有人可以对这种做法发表评论吗?这是生成的pom.xml:
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.5.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-ws</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-test</artifactId>
<version>2.2.1.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-security</artifactId>
</dependency>
<dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>1.6.18</version>
<!-- <type>jar</type> -->
<!-- <scope>compile</scope> -->
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5</version>
<scope>provided</scope>
</dependency>
</dependencies>
答案 0 :(得分:0)
事实上我遇到了同样的问题,这个答案对我有帮助。当使用Maven将依赖项添加到wss4j时,您可以选择添加bundle或zip / source引用,从而产生如下依赖项:
<dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>1.6.19</version>
<type>zip</type>
<classifier>source-release</classifier>
</dependency>
这导致了NoClassDefFoundError。我通过删除上面答案中提到的类型和分类器元素来实现它:
<dependency>
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
<version>1.6.19</version>
</dependency>
经过这次修正后,我的代码运行良好。顺便说一句,我没有必要在上面的答案中添加任何其他依赖项。