小编pgn*_*ngp的帖子

使用 REST Assured 进行测试时出现 java.lang.AbstractMethodError

我正在尝试使用 测试在我的控制器类中定义的 REST api REST Assured v4.3.0,但是我java.lang.AbstractMethodError在运行测试时得到了。我知道发生此错误是因为我正在调用一个抽象方法,但我很难解决它。

似乎错误是由于.body(is(equalTo("success")))in发生的,SampleControllerTest.java因为当我删除此行时,测试成功。我尝试了一些方法来解决它,但没有取得任何成功:

  • 在线搜索建议和示例,但它们要么是针对旧版本的,要么与 io.rest-assured/spring-mock-mvc
  • 尝试了不同的匹配器(org.hamcrest.Matchers.*org.hamcrest.CoreMatchers.*
  • 尝试org.hamcrest/hamcrest在 pom 文件中显式添加依赖项

这是我的代码供您参考:

代码结构:

test
|- src/
|  |- main/
|  |  |- java/
|  |  |  |- org/
|  |  |  |  |- example/
|  |  |  |  |  |- Application.java
|  |  |  |  |  |- SampleController.java
|  |- test/
|  |  |- java/
|  |  |  |- org/
|  |  |  | …
Run Code Online (Sandbox Code Playgroud)

java junit maven rest-assured spring-boot

14
推荐指数
5
解决办法
9910
查看次数

Spring boot 项目给出“应用程序运行失败”错误

我有一个 spring-boot maven 项目,它给出了Application run failed( java.lang.NoSuchFieldError: logger) 错误。

\n\n

当我使用运行此应用程序时mvn spring-boot:run -pl application,我得到的是:

\n\n
2018-06-13 16:09:17.439  WARN 9069 --- [           main] o.s.b.c.e.EventPublishingRunListener     : Error calling ApplicationEventListener\n\njava.lang.NoSuchFieldError: logger\n    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:248) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]\n    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:204) ~[spring-beans-5.0.7.RELEASE.jar:5.0.7.RELEASE]\n    at org.springframework.boot.autoconfigure.condition.ConditionEvaluationReport.get(ConditionEvaluationReport.java:169) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]\n    at org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener.logAutoConfigurationReport(ConditionEvaluationReportLoggingListener.java:96) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]\n    at org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener.onApplicationEvent(ConditionEvaluationReportLoggingListener.java:80) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]\n    at org.springframework.boot.autoconfigure.logging.ConditionEvaluationReportLoggingListener$ConditionEvaluationReportListener.onApplicationEvent(ConditionEvaluationReportLoggingListener.java:137) ~[spring-boot-autoconfigure-2.0.1.RELEASE.jar:2.0.1.RELEASE]\n    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172) [spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]\n    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:158) [spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]\n    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139) [spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]\n    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127) [spring-context-5.0.5.RELEASE.jar:5.0.5.RELEASE]\n    at org.springframework.boot.context.event.EventPublishingRunListener.failed(EventPublishingRunListener.java:126) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]\n    at org.springframework.boot.SpringApplicationRunListeners.callFailedListener(SpringApplicationRunListeners.java:91) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]\n    at org.springframework.boot.SpringApplicationRunListeners.failed(SpringApplicationRunListeners.java:84) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]\n    at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:812) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]\n    at org.springframework.boot.SpringApplication.run(SpringApplication.java:338) [spring-boot-2.0.1.RELEASE.jar:2.0.1.RELEASE]\n    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255) …
Run Code Online (Sandbox Code Playgroud)

java spring maven spring-boot

6
推荐指数
1
解决办法
3万
查看次数

在 Windows 7 上使用 Python CronTab 调度 Python 脚本

我想在 Windows 平台上使用 python-crontab 模块安排一个 python 脚本。发现以下代码片段可以解决,但配置起来很困难。脚本名称cronTest.py

from crontab import CronTab
file_cron = CronTab(tabfile='filename.tab')
mem_cron = CronTab(tab="""
* * * * * command
""")
Run Code Online (Sandbox Code Playgroud)

举例来说,我想使用以下名为 的脚本打印 5 分钟的日期和时间dateTime.py

import datetime
with open('dateInfo.txt','a') as outFile:
    outFile.write('\n' + str(datetime.datetime.now()))
Run Code Online (Sandbox Code Playgroud)

如何dateTime.py每 5 分钟执行一次并设置 cron 作业cronTest.py

python windows cron scheduled-tasks python-3.x

5
推荐指数
1
解决办法
1万
查看次数

捕获请求 python 上的代理错误

我是 Python 新手,所以遇到了一些麻烦。我正在尝试构建一个工具,通过代理将数据发布到外部服务器。我可以正常工作,但问题是我不知道如何捕获代理连接错误并打印其他内容。我写的代码是:

import requests
from bs4 import BeautifulSoup

headers = {
    "User-Agent": "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.11) Gecko/2009060215 Firefox/3.0.11",
    "Content-Type": "application/json"
}
proxies = { 
    "https": "https://244.324.324.32:8081",
}
data = {"test": "test"}
r = requests.post("https://example.com/page", proxies=proxies, json=data, headers=headers)
print(r.text)
Run Code Online (Sandbox Code Playgroud)

当代理已死(未连接/工作)或类似内容时,如何打印,例如“代理连接错误”。这是我第一次使用 python,所以我遇到了麻烦。

谢谢你

python proxy python-requests

3
推荐指数
1
解决办法
3815
查看次数