2013-09-27 55 views
1

這個線程解決了我在WAR(JSF 2)項目中遇到的問題,但是當項目是EAR時,此解決方案不工作。logback的問題

Logback and Jboss 7 - don't work together?

我使用JBoss 7.1。

UPDATE:

我在Eclipse中創建一個新的JSF項目(JBoss的工具和JBoss 7.1運行時)。添加jar 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! 

但在一個WAR項目返回

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

,我創建了一個JBoss的部署,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項目時,問題將返回。

有什麼想法?

+0

爲什麼這個解決方案不適合你?這是怎麼回事? – Math

+0

當項目簡單WAR時,將文件jboss-deployment-structure.xml放入WEB-INF目錄下解決錯誤:異常開始過濾器WicketFilter:java.lang.ClassCastException:ch.qos.logback.classic.LoggerContext無法投射ch.qos.logback.classic.LoggerContext。但是,當WAR項目是EAR項目時,此錯誤仍然存​​在 –

+0

如果您可以在您的問題中添加這些信息,那將是非常好的。沒有任何格式是一種難以理解的。這個行爲可能會鼓勵人們閱讀你的問題並回答它。如果您發佈您認爲需要調整的代碼片段會更好。 – Math

回答

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> 

非常感謝!!!!