0
當我不使用openJpa時,我的EAR應用程序運行良好。一旦我使用開放的JPA,我得到「SLF4J無法加載類blaaa」。如何配置openJpa模塊以使用我從pom.xml提供的SL4J並避免該錯誤?使用openJpa模塊時,slf4j不能在JBOSS中工作
我使用JBoss 7.1.1
的pom.xml
<properties>
<slf4j.version>1.7.3</slf4j.version>
<logback.version>1.0.10</logback.version>
</properties>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>${logback.version}</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
<version>${logback.version}</version>
</dependency>
.......
OpenJPA的module.xml
<module xmlns="urn:jboss:module:1.1" name="org.apache.openjpa">
<resources>
<resource-root path="openjpa-2.2.0.jar"/>
<resource-root path="openjpa-all-2.2.0.jar"/>
</resources>
<dependencies>
<module name="javax.persistence.api"/>
<module name="javax.transaction.api"/>
<module name="javax.validation.api"/>
<module name="org.apache.commons.lang"/>
<module name="org.apache.commons.collections"/>
<module name="org.slf4j"/>
</dependencies>
</module>
JBoss的部署,structure.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>
錯誤
10:17:53,854 ERROR [stderr] (MSC service thread 1-4) SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
10:17:53,860 ERROR [stderr] (MSC service thread 1-4) SLF4J: Defaulting to no-operation (NOP) logger implementation
10:17:53,866 ERROR [stderr] (MSC service thread 1-4) SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
10:17:53,873 SEVERE [javax.enterprise.resource.webcontainer.jsf.config] (MSC service thread 1-4) Critical error during deployment: : java.lang.LinkageError: loader constraint violation: when resolving interface method "org.slf4j.ILoggerFactory.getLogger(Ljava/lang/String;)Lorg/slf4j/Logger;" the class loader (instance of org/jboss/modules/ModuleClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of org/jboss/modules/ModuleClassLoader) for resolved class, org/slf4j/ILoggerFactory, have different Class objects for the type org/slf4j/Logger used in the signature
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242) [openjpa-all-2.2.0.jar:2.2.0]
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254) [openjpa-all-2.2.0.jar:2.2.0]
at net.sf.ehcache.CacheManager.<clinit>(CacheManager.java:131) [ehcache-ee-2.6.2.jar:]
at com.zreflect.emyed.whiteboard.controller.CacheController.<init>(CacheController.java:39) [classes:]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.6.0_25]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [rt.jar:1.6.0_25]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [rt.jar:1.6.0_25]
at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [rt.jar:1.6.0_25]
at java.lang.Class.newInstance0(Class.java:355) [rt.jar:1.6.0_25]
at java.lang.Class.newInstance(Class.java:308) [rt.jar:1.6.0_25]
at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:188) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:102) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:256) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:255) [jsf-impl-2.1.7-jbossorg-2.jar:]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_25]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_25]
10:17:54,007 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/emyed-whiteboard]] (MSC service thread 1-4) Exception sending context initialized event to listener instance of class com.sun.faces.config.ConfigureListener: java.lang.RuntimeException: java.lang.LinkageError: loader constraint violation: when resolving interface method "org.slf4j.ILoggerFactory.getLogger(Ljava/lang/String;)Lorg/slf4j/Logger;" the class loader (instance of org/jboss/modules/ModuleClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of org/jboss/modules/ModuleClassLoader) for resolved class, org/slf4j/ILoggerFactory, have different Class objects for the type org/slf4j/Logger used in the signature
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:292) [jsf-impl-2.1.7-jbossorg-2.jar:]
at org.apache.catalina.core.StandardContext.contextListenerStart(StandardContext.java:3392) [jbossweb-7.0.13.Final.jar:]
at org.apache.catalina.core.StandardContext.start(StandardContext.java:3850) [jbossweb-7.0.13.Final.jar:]
at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886) [rt.jar:1.6.0_25]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908) [rt.jar:1.6.0_25]
at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_25]
Caused by: java.lang.LinkageError: loader constraint violation: when resolving interface method "org.slf4j.ILoggerFactory.getLogger(Ljava/lang/String;)Lorg/slf4j/Logger;" the class loader (instance of org/jboss/modules/ModuleClassLoader) of the current class, org/slf4j/LoggerFactory, and the class loader (instance of org/jboss/modules/ModuleClassLoader) for resolved class, org/slf4j/ILoggerFactory, have different Class objects for the type org/slf4j/Logger used in the signature
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:242) [openjpa-all-2.2.0.jar:2.2.0]
at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:254) [openjpa-all-2.2.0.jar:2.2.0]
at net.sf.ehcache.CacheManager.<clinit>(CacheManager.java:131) [ehcache-ee-2.6.2.jar:]
at com.zreflect.emyed.whiteboard.controller.CacheController.<init>(CacheController.java:39) [classes:]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [rt.jar:1.6.0_25]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) [rt.jar:1.6.0_25]
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) [rt.jar:1.6.0_25]
at java.lang.reflect.Constructor.newInstance(Constructor.java:513) [rt.jar:1.6.0_25]
at java.lang.Class.newInstance0(Class.java:355) [rt.jar:1.6.0_25]
at java.lang.Class.newInstance(Class.java:308) [rt.jar:1.6.0_25]
at com.sun.faces.mgbean.BeanBuilder.newBeanInstance(BeanBuilder.java:188) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.mgbean.BeanBuilder.build(BeanBuilder.java:102) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.mgbean.BeanManager.createAndPush(BeanManager.java:409) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:269) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.mgbean.BeanManager.create(BeanManager.java:256) [jsf-impl-2.1.7-jbossorg-2.jar:]
at com.sun.faces.config.ConfigureListener.contextInitialized(ConfigureListener.java:255) [jsf-impl-2.1.7-jbossorg-2.jar:]
... 8 more
我還包含了jboss-deployment-structure.xml和lib只有一個版本的slf4j。如果我不包含openjpa,我不會收到任何錯誤。我認爲這是openjpa的問題。 – user1595858 2013-04-25 16:11:05
你如何包含OpenJPA?通過模塊或部署的lib目錄? – 2013-04-25 17:21:16
我已經通過模塊 – user1595858 2013-04-25 19:10:00