Logback和Jboss 7-不能一起工作吗? [英] Logback and Jboss 7 - don't work together?

查看:130
本文介绍了Logback和Jboss 7-不能一起工作吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题.我有这个Java应用程序,该Java应用程序先前已部署在tomcat中,并愉快地将经典的logback用作slf4j实现.现在,当我们尝试在jboss 7.1.final服务器中部署同一应用程序时,它甚至没有部署该应用程序. java.lang.ClassCastException: org.slf4j.impl.Slf4jLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext 这是令人反感的代码行

I am having a curious problem. I had this Java application which was previously deployed in tomcat and happily used logback classic as an slf4j implementation. Now when we tried to deploy the same app in a jboss 7.1.final server it doesn't even deploy the application maoning about java.lang.ClassCastException: org.slf4j.impl.Slf4jLoggerFactory cannot be cast to ch.qos.logback.classic.LoggerContext This is the offending line of code

final LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();

具有他的类的是弹簧注入的,并且失败了-因此无法部署整个应用程序.有人对此有解决方案吗?预先感谢

The class that has his is spring injected and that is failing - hence the whole application cannot be deployed. Anyone got a solution to this? Thanks in advance

在该站点以及其他论坛中浏览后,我意识到Jboss 7捆绑了它自己的slf4j实现,并实现了与LogbackContext在logback中相同的ILoggerFactory接口.我们的应用程序尝试获取相同的实例,但是应用程序服务器强加了它自己的slf4j实现.

After looking in this site plus other forums I realised that Jboss 7 comes bundled with it's own slf4j implementation and implement the same ILoggerFactory interface that LoggerContext in logback does. Our application tried to get an instance of the same but the app server imposes it's own slf4j implementation.

我试图修改jboss \ modules \ org \ slf4j \ impl \ main中的module.xml并将其指向回传jar.

I tried to modify the module.xml in jboss\modules\org\slf4j\impl\main and pointed it to logback jars.

<resources>
    <resource-root path="logback-classic-0.9.28.jar"/>
    <resource-root path="logback-core-0.9.28.jar"/>
</resources>

现在,当我启动应用程序时,我遇到了严重错误

Now when I start the application I am getting a serious error

Exception starting filter WicketFilter: java.lang.ClassCastException: ch.qos.logback.classic.LoggerContext cannot be cast to ch.qos.logback.classic.LoggerContext

我精疲力尽.任何jboss和logback专家都可以提供帮助吗? 预先感谢

I am at my wits end. Any jboss and logback experts can help? Thanks in advance

推荐答案

您需要从部署中排除服务器版本slf4j.创建一个jboss-deployment-structure.xml文件并将其放置在WARS META-INFWEB-INF目录中.

You need to exclude the servers version of slf4j from your deployment. Create a jboss-deployment-structure.xml file and place it in either your WARS META-INF or WEB-INF directory.

文件内容应如下所示:

<jboss-deployment-structure>
    <deployment>
        <!-- Exclusions allow you to prevent the server from automatically adding some dependencies     -->
        <exclusions>
            <module name="org.slf4j" />
            <module name="org.slf4j.impl" />
        </exclusions>
    </deployment>
</jboss-deployment-structure>

这篇关于Logback和Jboss 7-不能一起工作吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆