为什么我会遇到错误的“在使用重新安装的Java库运行代码时?
在使用重新安装的Java库运行代码时,我会在RESTHRED保证框架中遇到错误的响应式窗口。我正在使用POM文件中的4.5.1休息版。有人面对类似问题吗?需要输入。
**Error:**
java.lang.NoSuchMethodError: 'org.hamcrest.Matcher org.hamcrest.core.IsInstanceOf.any(java.lang.Class)'
at org.hamcrest.Matchers.any(Matchers.java:349)
at io.restassured.filter.log.ResponseLoggingFilter.<init>(ResponseLoggingFilter.java:73)
at io.restassured.filter.log.ResponseLoggingFilter.logResponseTo(ResponseLoggingFilter.java:182)
**Framework Utility:**
public RequestSpecification setBaseURI() throws IOException {
if (requestSpec == null) {
baseURL = System.getProperty("baseURL", config.getConfig().getProperty("BASE_URL"));
log.info(baseURL);
config.setProperty("APIBase.properties");
RestAssured.urlEncodingEnabled = false;
PrintStream log = new PrintStream(new FileOutputStream("log.txt"));
requestSpec = new RequestSpecBuilder().
setBaseUri(config.getConfig().getProperty("BASE_URL"))
.addFilter(RequestLoggingFilter.logRequestTo(log))
.addFilter(ResponseLoggingFilter.logResponseTo(log))
.build();
}
return requestSpec;
}
**POM.xml**
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.5.1</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured-common</artifactId>
<version>4.5.1</version>
</dependency>
I am getting the error for ResponseLoggingFilter in Rest Assured framework while running the code with RestAssured java libraries. I am using the 4.5.1 rest assured version in the POM file. Has anybody faced the similar issue? Need inputs.
**Error:**
java.lang.NoSuchMethodError: 'org.hamcrest.Matcher org.hamcrest.core.IsInstanceOf.any(java.lang.Class)'
at org.hamcrest.Matchers.any(Matchers.java:349)
at io.restassured.filter.log.ResponseLoggingFilter.<init>(ResponseLoggingFilter.java:73)
at io.restassured.filter.log.ResponseLoggingFilter.logResponseTo(ResponseLoggingFilter.java:182)
**Framework Utility:**
public RequestSpecification setBaseURI() throws IOException {
if (requestSpec == null) {
baseURL = System.getProperty("baseURL", config.getConfig().getProperty("BASE_URL"));
log.info(baseURL);
config.setProperty("APIBase.properties");
RestAssured.urlEncodingEnabled = false;
PrintStream log = new PrintStream(new FileOutputStream("log.txt"));
requestSpec = new RequestSpecBuilder().
setBaseUri(config.getConfig().getProperty("BASE_URL"))
.addFilter(RequestLoggingFilter.logRequestTo(log))
.addFilter(ResponseLoggingFilter.logResponseTo(log))
.build();
}
return requestSpec;
}
**POM.xml**
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.5.1</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured-common</artifactId>
<version>4.5.1</version>
</dependency>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据StackTrace的说法,缺少方法具有此签名:
根据POM文件,静止保证的4.5.1将Hamcrest 2.1作为依赖关系。
在Hamcrest 2.1中,
任何
方法都被声明为:删除的类型签名将为
org.hamcrest.matcher any(java.lang.class)
... JVM正在寻找什么。陌生人和陌生人...
以某种方式,JVM正在加载一个没有该特定
任何
方法的Hamcrest版本。但是根据GIT历史记录...所有官方版本的Hamcrest都有一个该签名的任何方法,一直返回到Hamcrest 1.0。确实,该方法在1.0和2.2之间没有更改...这是最新的官方版本。您确定自己从可靠的地方获得了其余的和hamcrest罐子吗?
接下来要做的是检查您实际使用的罐子,检查其版本以及它们来自何处,打开它们,并使用
Javap
对各自的“ .class”文件进行检查。According to the stacktrace, missing method has this signature:
According to the POM file, rest-assured 4.5.1 has hamcrest 2.1 as a dependency.
In Hamcrest 2.1, the
any
method is declared as:The erased type signature will be
org.hamcrest.Matcher any(java.lang.Class)
... which is exactly what the JVM is looking for.Stranger, and stranger ...
Somehow the JVM is loading a version of Hamcrest that doesn't have that particular
any
method. But according to the Git history ... all official versions of Hamcrest have anany
method with that signature, all the way back to Hamcrest 1.0. Indeed, the method hasn't changed between 1.0 and 2.2 ... which is the latest official release.Are you sure that you are getting the Rest-Assured and Hamcrest JARs from a reliable place?
The next thing to do would be to examine the JARs that you are actually using, check their versions and where they came from, unpack them, and examine the respective ".class" files forensically with a
javap
.