【问题标题】:Reference to log4j.xml broken after maven dependency spring-data-rest-webmvc, packages abbreviatedmaven依赖spring-data-rest-webmvc后引用log4j.xml坏了,包缩写
【发布时间】:2013-01-29 12:54:38
【问题描述】:

我的 (java) Spring 3 项目有问题:

我在“spring-data-rest-webmvc”(版本 1 到 1.0.0-RC3)中包含了一个 maven 依赖项,其中不再使用标准 log4j.xml。相反,它似乎使用了一些其他属性日志文件(我找不到),而不是在我的包中,也不是在 spring-data-rest-webmvc 源中。

加上日志链接问题,包名都是缩写,我觉得很奇怪(至少是出乎意料的)。

我确实想使用这个 Spring 包来轻松地创建安静的 Web 服务。

我想在使用 spring 包时控制我的 log4j 属性文件。顺便说一句,似乎使用了三个日志系统(log4j、slf4j 和 commons-logging),应该不是问题吧?

【问题讨论】:

    标签: spring logging spring-data-rest


    【解决方案1】:

    没有代码很难判断,但最有可能发生的情况是,当您添加 spring-data-rest-webmvc 依赖项时,您的项目已经依赖于 logback-classic。

    如果你把文件logback.xml和下面的内容放在log4j.xml旁边,log4j会被重新拾取。

    <configuration>
    <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>
                %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n
            </pattern>
        </encoder>
    </appender>
    <logger name="org.springframework.data.rest" level="INFO" />
    <root level="INFO">
        <appender-ref ref="stdout" />
    </root>
    </configuration>
    

    【讨论】:

      【解决方案2】:

      或者,要摆脱这个 DEBUG 级别的输出,只需排除 logback 依赖。在 Maven 中它将是:

      <dependency>
          <groupId>org.springframework.data</groupId>
          <artifactId>spring-data-rest-webmvc</artifactId>
          <exclusion>
              <groupId>ch.qos.logback</groupId>
              <artifactId>logback-classic</artifactId>
          </exclusion>
      </dependency>
      

      【讨论】:

        猜你喜欢
        • 2012-11-12
        • 2016-10-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-07-20
        • 2020-07-05
        • 1970-01-01
        • 2019-09-02
        相关资源
        最近更新 更多