gpt4 book ai didi

java - SpringBootTest 和 MockMvc 创建了大量的控制台日志记录 - 如何禁用?

转载 作者:行者123 更新时间:2023-12-01 14:10:33 24 4
gpt4 key购买 nike

我们使用带有 @SpringBootTest 属性的 @Autowired private MockMvc mockMvc 来模拟对 Controller 类的 HTTP 请求。

出于某种我们似乎无法确定的原因,这为每个测试用例创建了大量日志记录,并且正在用数千行文本填充我们的日志,如下所示:

build   18-May-2019 03:09:40    Async:
build 18-May-2019 03:09:40 Async started = false
build 18-May-2019 03:09:40 Async result = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 Resolved Exception:
build 18-May-2019 03:09:40 Type = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 ModelAndView:
build 18-May-2019 03:09:40 View name = null
build 18-May-2019 03:09:40 View = null
build 18-May-2019 03:09:40 Model = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 FlashMap:
build 18-May-2019 03:09:40 Attributes = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 MockHttpServletResponse:
build 18-May-2019 03:09:40 Status = 200
build 18-May-2019 03:09:40 Error message = null
build 18-May-2019 03:09:40 Headers = {X-Content-Type-Options=[nosniff], X-XSS-Protection=[1; mode=block], Cache-Control=[no-cache, no-store, max-age=0, must-revalidate], Pragma=[no-cache], Expires=[0], X-Frame-Options=[DENY]}
build 18-May-2019 03:09:40 Content type = null
build 18-May-2019 03:09:40 Body =
build 18-May-2019 03:09:40 Forwarded URL = null
build 18-May-2019 03:09:40 Redirected URL = null
build 18-May-2019 03:09:40 Cookies = []
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 MockHttpServletRequest:
build 18-May-2019 03:09:40 HTTP Method = POST
build 18-May-2019 03:09:40 Request URI = /api/v1/certification/applications
build 18-May-2019 03:09:40 Parameters = {}
build 18-May-2019 03:09:40 Headers = {Content-Type=[application/json;charset=UTF-8]}
build 18-May-2019 03:09:40 Body = {"applicationVersion":"1.0"}
build 18-May-2019 03:09:40 Session Attrs = {}
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 Handler:
build 18-May-2019 03:09:40 Type = <redacted>
build 18-May-2019 03:09:40 Method = <redacted>
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 Async:
build 18-May-2019 03:09:40 Async started = false
build 18-May-2019 03:09:40 Async result = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 Resolved Exception:
build 18-May-2019 03:09:40 Type = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 ModelAndView:
build 18-May-2019 03:09:40 View name = null
build 18-May-2019 03:09:40 View = null
build 18-May-2019 03:09:40 Model = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 FlashMap:
build 18-May-2019 03:09:40 Attributes = null
build 18-May-2019 03:09:40
build 18-May-2019 03:09:40 MockHttpServletResponse:
build 18-May-2019 03:09:40 Status = 200
build 18-May-2019 03:09:40 Error message = null
build 18-May-2019 03:09:40 Headers = {X-Content-Type-Options=[nosniff], X-XSS-Protection=[1; mode=block], Cache-Control=[no-cache, no-store, max-age=0, must-revalidate], Pragma=[no-cache], Expires=[0], X-Frame-Options=[DENY]}
build 18-May-2019 03:09:40 Content type = null
build 18-May-2019 03:09:40 Body =
build 18-May-2019 03:09:40 Forwarded URL = null
build 18-May-2019 03:09:40 Redirected URL = null
build 18-May-2019 03:09:40 Cookies = []

我所有的互联网搜索和 Spring Boot 测试文档阅读都没有结果。 这个日志记录 来自哪里,我们如何关闭它?

我们已经详尽地扫描了我们的代码,并且确信我们不打印/不负责它。

最佳答案

这是来自 MockMvc

看起来您可能已经覆盖了默认值并指示 Spring Boot 始终打印 MockMvc 的调试输出。

您应该能够通过声明 @AutoConfigureMockMvc(printOnlyOnFailure = true) 或省略 printOnlyOnFailure 标志来停用它,因为 true 是默认值。

您可以通过 print 属性配置输出模式——例如, @AutoConfigureMockMvc(print = MockMvcPrint.NONE)

关于java - SpringBootTest 和 MockMvc 创建了大量的控制台日志记录 - 如何禁用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56199684/

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