具有logback的Spring Boot日志记录问题

时间:2014-08-16 23:18:46

标签: logging logback spring-boot

当我在传统的weblogic容器中部署Spring引导Web应用程序时,我有一些与日志相关的异常。相同的应用程序适用于嵌入式tomcat而不对其进行任何更改。

使用weblogic 12 c,我看到了这个异常:

  

     

    

              

     

at org.springframework.util.Assert.isInstanceOf(Assert.java:339)at at   org.springframework.boot.logging.logback.LogbackLoggingSystem.initialize(LogbackLoggingSystem.java:92)     在   org.springframework.boot.logging.AbstractLoggingSystem.initializeWithSensibleDefaults(AbstractLoggingSystem.java:62)     在   org.springframework.boot.logging.AbstractLoggingSystem.beforeInitialize(AbstractLoggingSystem.java:45)     在   org.springframework.boot.logging.logback.LogbackLoggingSystem.beforeInitialize(LogbackLoggingSystem.java:68)     在   org.springframework.boot.logging.LoggingApplicationListener.onApplicationEvent(LoggingApplicationListener.java:131)     在   org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:98)     在   org.springframework.boot.context.event.EventPublishingRunListener.publishEvent(EventPublishingRunListener.java:92)     在   org.springframework.boot.context.event.EventPublishingRunListener.started(EventPublishingRunListener.java:53)     在   org.springframework.boot.SpringApplication.run(SpringApplication.java:269)     在   org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:142)     在   org.springframework.boot.context.web.SpringBootServletInitializer.createRootApplicationContext(SpringBootServletInitializer.java:89)     在   org.springframework.boot.context.web.SpringBootServletInitializer.onStartup(SpringBootServletInitializer.java:51)     在   org.springframework.web.SpringServletContainerInitializer.onStartup(SpringServletContainerInitializer.java:175)     在   weblogic.servlet.internal.WebAppServletContext.initContainerInitializer(WebAppServletContext.java:1394)     在   weblogic.servlet.internal.WebAppServletContext.initContainerInitializers(WebAppServletContext.java:1331)     在   weblogic.servlet.internal.WebAppServletContext.initContainerInitializers(WebAppServletContext.java:1317)     在   weblogic.servlet.internal.WebAppServletContext.preloadResources(WebAppServletContext.java:1834)     在   weblogic.servlet.internal.WebAppServletContext.start(WebAppServletContext.java:2876)     在   weblogic.servlet.internal.WebAppModule.startContexts(WebAppModule.java:1661)     在   weblogic.servlet.internal.WebAppModule.start(WebAppModule.java:823)     在   weblogic.application.internal.ExtensibleModuleWrapper $ StartStateChange.next(ExtensibleModuleWrapper.java:360)     在   weblogic.application.internal.ExtensibleModuleWrapper $ StartStateChange.next(ExtensibleModuleWrapper.java:356)     在   weblogic.application.utils.StateMachineDriver.nextState(StateMachineDriver.java:42)     在   weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:138)

我在父pom中使用spring-platform 1.0.1。我的网络模块pom看起来像这样:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>people-mgmt</groupId>
    <artifactId>people-mgmt-data</artifactId>
    <version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-jasper</artifactId>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
</dependency>
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-test</artifactId>
    <scope>test</scope>
</dependency>

这是我的项目依赖树:

enter image description here enter image description here

我们将非常感谢您解决此问题的任何帮助。

1 个答案:

答案 0 :(得分:1)

是weblogic类加载器问题。请检查这些链接 - sl4j/logback under weblogichttp://blog.terrencemiao.com/archives/annoying-slf4j-problem-in-weblogic-server-12c

因此,通过在WEB-INF文件夹下的weblogic.xml中添加以下内容来解决此问题。

<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
    <container-descriptor>
        <prefer-application-packages>
            <package-name>org.slf4j</package-name>
        </prefer-application-packages>
    </container-descriptor>
</weblogic-web-app>