1

这个线程解决了我在 WAR (JSF 2) 项目中的问题,但是当项目是 EAR 时,这个解决方案不起作用。

Logback 和 Jboss 7 - 不一起工作?

我正在使用 JBOSS 7.1。

更新:

我在 Eclipse 中创建了一个新的 JSF 项目(JBoss Tools 和 JBOSS 7.1 运行时)。添加 jars slf4j-api-1.7.5.jar、logback-core-1.0.13.jar、logback-classic-1.0.13.jar 和 logback-access-1.0.13.jar。

bean中的这段代码:

@Named
public class BeanTeste {

private Logger log = LoggerFactory.getLogger(BeanTeste.class);

public void executar(){
log.debug("TESTE DE DEBUG");
log.info("TESTE DE INFO");
log.warn("TESTE DE WARN");

// print internal state
   LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
   StatusPrinter.print(lc);

System.out.println("METODO COMPLETADO!");
}

应该返回:

18:00:09,278 INFO  [stdout] (http--0.0.0.0-8080-1) 18:00:09.274 [http--0.0.0.0-8080-1] DEBUG com.br.teste.BeanTeste - TESTE DE DEBUG

18:00:09,280 INFO  [stdout] (http--0.0.0.0-8080-1) 18:00:09.279 [http--0.0.0.0-8080-1] INFO  com.br.teste.BeanTeste - TESTE DE INFO

18:00:09,282 INFO  [stdout] (http--0.0.0.0-8080-1) 18:00:09.282 [http--0.0.0.0-8080-1] WARN  com.br.teste.BeanTeste - TESTE DE WARN

18:00:09,284 INFO  [stdout] (http--0.0.0.0-8080-1) 18:00:09,223 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]

18:00:09,286 INFO  [stdout] (http--0.0.0.0-8080-1) 18:00:09,224 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]

18:00:09,288 INFO  [stdout] (http--0.0.0.0-8080-1) 18:00:09,224 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.xml]

18:00:09,291 INFO  [stdout] (http--0.0.0.0-8080-1) 18:00:09,225 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Setting up default configuration.

18:00:09,293 INFO  [stdout] (http--0.0.0.0-8080-1) 

18:00:09,293 INFO  [stdout] (http--0.0.0.0-8080-1) METODO COMPLETADO!

但返回

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

在一个 WAR 项目中,我创建了一个 jboss-deployment-structure.xml 文件并将其放在 WEB-INF 目录中并解决了我的问题。

<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>

当 WAR 项目添加一个 EAR 项目时,问题又回来了。

有任何想法吗?

4

1 回答 1

0

我用下面的内容更改了我的 jboss-deployment-structure.xml 并且它起作用了。

<?xml version="1.0" encoding="UTF-8"?>
<jboss-deployment-structure>
<ear-subdeployments-isolated>true</ear-subdeployments-isolated>
<deployment>
    <exclusions>
        <module name="org.apache.log4j" />
        <module name="org.slf4j" />
        <module name="org.slf4j.ext" />
        <module name="org.slf4j.impl" />
        <module name="org.slf4j.jcl-over-slf4j" />
        <module name="org.apache.commons.logging" />
        <module name="org.jboss.logging"/>
        <module name="org.jboss.logging.jul-to-slf4j-stub"/>
        <module name="org.jboss.logmanager"/>
        <module name="org.jboss.log4j.logmanager"/>
        <module name="org.apache.log4j"/>
        <module name="org.log4j"/>  
    </exclusions>
    <dependencies>
    </dependencies>
</deployment>
<sub-deployment name="Teste.war">
    <exclusions>
        <module name="org.apache.log4j" />
        <module name="org.slf4j" />
        <module name="org.slf4j.ext" />
        <module name="org.slf4j.impl" />
        <module name="org.slf4j.jcl-over-slf4j" />
        <module name="org.apache.commons.logging" />
        <module name="org.jboss.logging"/>
        <module name="org.jboss.logging.jul-to-slf4j-stub"/>
        <module name="org.jboss.logmanager"/>
        <module name="org.jboss.log4j.logmanager"/>
        <module name="org.apache.log4j"/>
        <module name="org.log4j"/>  
    </exclusions>
</sub-deployment>
<sub-deployment name="TesteEJB.jar">
    <exclusions>
        <module name="org.apache.log4j" />
        <module name="org.slf4j" />
        <module name="org.slf4j.ext" />
        <module name="org.slf4j.impl" />
        <module name="org.slf4j.jcl-over-slf4j" />
        <module name="org.apache.commons.logging" />
        <module name="org.jboss.logging"/>
        <module name="org.jboss.logging.jul-to-slf4j-stub"/>
        <module name="org.jboss.logmanager"/>
        <module name="org.jboss.log4j.logmanager"/>
        <module name="org.apache.log4j"/>
        <module name="org.log4j"/>  
    </exclusions>
</sub-deployment>

多谢!!!!

于 2013-10-01T15:02:27.403 回答