请帮助我验证响应正文的架构。我遇到运行时错误。:
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 中
<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/