You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spring Boot测试中无法屏蔽Spring Test Context相关日志的问题求助

Spring Boot测试中无法屏蔽Spring Test Context相关日志的问题求助

我有一批放在com.company.integration包下的集成测试,现在想减少输出的日志量,特别是要屏蔽下面这类日志:

17:41:31.875 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
17:41:31.879 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
17:41:31.887 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.company.integration.EndpointControllerTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
17:41:31.891 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.company.integration.EndpointControllerTest], using SpringBootContextLoader

我已经尝试过的方法

  • 在各个测试类(包括所有测试类继承的、带有@SpringBootTest注解的父类)上添加如下注解:
@TestPropertySource(properties = {
    "logging.level.org.springframework.test.context=ERROR",
    "logging.level.org.springframework.test.context.cache=ERROR",
    "logging.level.org.springframework.boot.test.context=ERROR",
    "logging.level.root=ERROR"
})
  • 在@SpringBootTest注解中直接配置属性:
@SpringBootTest(properties = {
    "logging.level.org.springframework.test.context=ERROR",
    "logging.level.org.springframework.test.context.cache=ERROR",
    "logging.level.org.springframework.boot.test.context=ERROR",
    "logging.level.root=ERROR"
})
  • 在test-application.properties配置文件以及主应用的application.properties中添加配置:
logging.level.root=ERROR
logging.level.org.springframework.test.context=ERROR
logging.level.org.springframework.boot.test.context=ERROR
logging.level.org.springframework.context=ERROR
logging.level.org.springframework=ERROR

但以上方法都没能屏蔽掉目标日志,我是不是漏掉了什么?有没有办法能成功屏蔽这些日志?

备注:内容来源于stack exchange,提问作者aCarella

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 20:09:31