gpt4 book ai didi

java - Hamcrest Matcher 签名者信息与同一包中其他类的签名者信息不匹配

转载 作者:行者123 更新时间:2023-12-04 11:41:05 25 4
gpt4 key购买 nike

我正在尝试使用 REST-Assured 和 JUnit5 在我的 Spring Boot 应用程序中编写一些集成测试,但是当我运行以下命令时:

@SpringBootTest(classes = ProductsApplication.class)
class ProductsApiTest {

@Before
public void setup() {
RestAssured.baseURI = "http://localhost:8080/test/api/products";
}

@Test
public void test1() {
ValidatableResponse statusCode = given().when().get().then().statusCode(200);
}
}

出现一个令人讨厌的错误:

java.lang.SecurityException: class "org.hamcrest.Matchers"'s signer information does not match signer information of other classes in the same package



请看一下我的 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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>

...
<dependencies>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<scope>test</scope>
</dependency>

...
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
</dependency>
</dependencies>

<build>
...
</build>
</project>

以下是 Eclipse 项目使用的 Order 和 Export + Libraries:
enter image description here

enter image description here

如何设置 Eclipse 环境以使用 REST-Assured 和 Hamcrest?为什么会抛出这个异常?

最佳答案

我从我的 .p2 插件文件夹中删除了 org.hamcrest.core_1.3.0.v201303031735.jar,它对我有用。

  • 我在“C:\Users\Dell.p2\pool\plugins”文件夹中搜索了“hamcrest”,并在那里找到了“org.hamcrest.core_1.3.0.v201303031735.jar”。
  • 我为此路径删除了它。
  • 尝试运行测试用例,它在 statusCode() 中没有失败地通过了。方法行。

  • 请建议是否有人有更好的解决方案。

    关于java - Hamcrest Matcher 签名者信息与同一包中其他类的签名者信息不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59963733/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com