java - RestAssured_Class Not Found_com/github/fge/jsonschema/main/JsonSchemaFactory

标签 java rest-assured

请帮助我验证响应正文的架构。我遇到运行时错误。:

Exception in thread "main" java.lang.NoClassDefFoundError: com/github/fge/jsonschema/main/JsonSchemaFactory

import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.response.Response;
import io.restassured.response.ValidatableResponse;
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;
import static io.restassured.RestAssured.*;
public class Sample_JsonSchemaValidation {

        public static void main(String[] args) {
            // TODO Auto-generated method stub


            //ClassLoader loader = Sample_JsonSchemaValidation.class.getClassLoader();
            //System.out.println(loader.getResource("Sample_JsonSchemaValidation.class"));



    RestAssured.baseURI = "https://reqres.in/";             
                     given().contentType(ContentType.JSON).queryParam("id", 2).
                     when().get("api/users/").                   then().body(matchesJsonSchemaInClasspath("JsonSchemavalidator.json"));              

        }
}

请帮助解决该错误。

最佳答案

您的 POM 中有以下内容吗?

<dependency>
    <groupId>io.rest-assured</groupId>
    <artifactId>json-schema-validator</artifactId>
    <version>4.3.0</version>
</dependency>

编译依赖项包括 2 个工件,如果您没有它们,请将它们也包含在您的 POM 中

enter image description here

<dependency>
    <groupId>com.github.java-json-tools</groupId>
    <artifactId>json-schema-validator</artifactId>
    <version>2.2.10</version>
</dependency>

关于java - RestAssured_Class Not Found_com/github/fge/jsonschema/main/JsonSchemaFactory,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61849002/

相关文章:

rest-assured - 如何根据条件选择发送参数?

java - 异步 Spring 远程处理 (AMQP) 客户端

java - 如何对通用对的集合进行排序

java - 多个 JSlider 相互 react 始终等于 100%

java - 如何在java中采用输入("\n")分隔并以双输入(“\n\n)结尾的多行字符串输入?

java - 如何在 Java 中使用 REST-assured 上传 CSV 文件?

java - 使用 Facebook4j api 从页面获取帖子

java - MockMvc、RestAssured 和 TestRestTemplate 有什么区别?

java - 在 JAVA 中如何获取 JSON 属性并将其存储在数组中?

带有内容类型 : text/html with injected html tags 的 java REST 保证响应正文