logback-spring.xml无法使用目标重新打包?

时间:2017-04-18 16:54:54

标签: spring-boot logback

我首先想要在特定的活动配置文件中禁用控制台输出。

我已经设置了一个新的tomcat(8.5.12)并且只部署了一个“spring-boot-hello-world”应用程序,类似于tutorial

包装类型是经典war - 所以我改变了我的pom如下:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
  http://maven.apache.org/xsd/maven-4.0.0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>org.springframework</groupId>
  <artifactId>gs-spring-boot</artifactId>
  <version>0.1.0</version>

  <packaging>war</packaging>

  <parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.5.2.RELEASE</version>
  </parent>

  <properties>
    <java.version>1.8</java.version>
  </properties>

  <build>
    <finalName>foo</finalName>
    <plugins>
      <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>repackage</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

  <dependencies>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-tomcat</artifactId>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
  </dependencies>
</project>

并从SpringBootServletInitializer扩展了我的应用程序。我没有使用System.out.println,而是添加了org.slf4j.Logger

如果我现在从howto添加logback-spring.xml,我会收到以下错误:

16:52:01.365 [localhost-startStop-2] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [java:comp/env/logging.exception-conversion-word]
16:52:01.367 [localhost-startStop-2] DEBUG org.springframework.jndi.JndiLocatorDelegate - Converted JNDI name [java:comp/env/logging.exception-conversion-word] not found - trying original name [logging.exception-conversion-word]. javax.naming.NameNotFoundException: Name [logging.exception-conversion-word] is not bound in this Context. Unable to find [logging.exception-conversion-word].

基于此SO-Question我在启动tomcat时添加了-Dlogback.statusListenerClass=ch.qos.logback.core.status.OnConsoleStatusListener。这导致以下结果。

16:22:33,891 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
16:22:33,891 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
16:22:33,891 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/tmp/apache-tomcat-8.5.12/webapps/foo/WEB-INF/classes/logback.xml]

查看指定位置,有以下文件/文件夹:

ls /tmp/apache-tomcat-8.5.12/webapps/foo/WEB-INF/classes/
hello  logback-spring.xml

如果我添加例如a(有效)logback-dev.xml,我在catalina.out中得到以下结果:

17:44:46,698 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
17:44:46,702 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
17:44:46,703 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.xml]

logback-spring.xmllogback.xml的回溯事件是否正常?或者这可能是一个错误?

使用'普通'logback.xml不允许我使用例如<springProfile name="dev"> here

如果我想使用不同的配置文件,我找到的唯一解决方案是提供logback-{stage}.xml并在相关的logging.config=classpath:logback-{stage}.xml文件中添加application-{stage}.properties - 这似乎有效。也不起作用!我可以添加logback-{stage}.xml而不起作用。但是,只要我将其包含在logging.config=classpath:logback-{stage}.xml中,我就会得到:

09:26:35.084 [localhost-startStop-2] DEBUG org.springframework.jndi.JndiTemplate - Looking up JNDI object with name [LOGGING_patternlevel]
09:26:35.084 [localhost-startStop-2] DEBUG org.springframework.jndi.JndiPropertySource - JNDI lookup for name [LOGGING_patternlevel] threw NamingException with message: Name [LOGGING_patternlevel] is not bound in this Context. Unable to find [LOGGING_patternlevel].. Returning null

0 个答案:

没有答案