代码之家  ›  专栏  ›  技术社区  ›  Synesso

为什么Spring信息记录为标准错误?

  •  1
  • Synesso  · 技术社区  · 14 年前

    我有许多数据库集成测试,它们使用以下注释进行事务回滚:

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations={"classpath:ApplicationContext-DAOs.xml"})
    @Transactional
    

    测试通过了,但当我运行它们时,Spring认为有必要在信息级别登录到标准错误!它记录了如下内容:

    19/11/2010 16:49:11 org.springframework.test.context.TestContextManager
      retrieveTestExecutionListeners
    INFO: @TestExecutionListeners is not present for class [class my.SomeDAOTest]:
      using defaults.
    etc for many, many lines ...
    

    我该在哪里关掉它?

    1 回复  |  直到 14 年前
        1
  •  1
  •   limc    14 年前

    您可以使用log4j隐藏它。在log4j.xml中,为spring设置一个日志以警告(或错误)。

    <logger name="org.springframework">
        <level value="warn"/>
    </logger>
    
        2
  •  1
  •   Matt Brunell    5 年前

    Spring核心使用apache commons日志记录。为了配置远离默认行为(写入stderr),我必须为我的特定框架使用桥接组件。

    我正在使用Log4j2,所以一旦我将apache commons的桥添加到Log4j2,spring core就会尊重我的设置。

    <dependency>
        <groupId>org.apache.logging.log4j</groupId>
        <artifactId>log4j-jcl</artifactId>
        <version>2.11.2</version>
    </dependency>