6

我希望也许有人以前遇到过这个问题并可以提供建议。我正在 Hibernate 4 和 Spring 3 上编写一个应用程序。这是我的依赖树:

+- javax.servlet:servlet-api:jar:2.5:provided
+- org.springframework:spring-webmvc:jar:3.1.3.RELEASE:compile
|  +- org.springframework:spring-asm:jar:3.1.3.RELEASE:compile
|  +- org.springframework:spring-beans:jar:3.1.3.RELEASE:compile
|  +- org.springframework:spring-context:jar:3.1.3.RELEASE:compile
|  +- org.springframework:spring-context-support:jar:3.1.3.RELEASE:compile
|  +- org.springframework:spring-core:jar:3.1.3.RELEASE:compile
|  +- org.springframework:spring-expression:jar:3.1.3.RELEASE:compile
|  \- org.springframework:spring-web:jar:3.1.3.RELEASE:compile
+- org.springframework:spring-orm:jar:3.1.3.RELEASE:compile
+- org.springframework:spring-jdbc:jar:3.1.3.RELEASE:compile
+- org.springframework:spring-tx:jar:3.1.3.RELEASE:compile
|  +- aopalliance:aopalliance:jar:1.0:compile
|  \- org.springframework:spring-aop:jar:3.1.3.RELEASE:compile
+- org.springframework.security:spring-security-core:jar:3.1.3.RELEASE:compile
+- org.springframework.security:spring-security-web:jar:3.1.3.RELEASE:compile
+- org.springframework.security:spring-security-config:jar:3.1.3.RELEASE:compile
+- org.hibernate.javax.persistence:hibernate-jpa-2.0-api:jar:1.0.1.Final:compile
+- org.hibernate:hibernate-core:jar:4.1.8.Final:compile
|  +- antlr:antlr:jar:2.7.7:compile
|  +- org.jboss.logging:jboss-logging:jar:3.1.0.GA:compile
|  +- org.jboss.spec.javax.transaction:jboss-transaction-api_1.1_spec:jar:1.0.0.Final:compile
|  +- dom4j:dom4j:jar:1.6.1:compile
|  +- org.javassist:javassist:jar:3.15.0-GA:compile
|  \- org.hibernate.common:hibernate-commons-annotations:jar:4.0.1.Final:compile
+- org.hibernate:hibernate-entitymanager:jar:4.1.8.Final:compile
+- org.hibernate:hibernate-validator:jar:4.3.0.Final:compile
+- javax.validation:validation-api:jar:1.0.0.GA:compile
+- commons-lang:commons-lang:jar:2.4:compile
+- commons-beanutils:commons-beanutils:jar:1.8.3:compile
+- commons-beanutils:commons-beanutils-core:jar:1.8.3:compile
+- commons-beanutils:commons-beanutils-bean-collections:jar:1.8.3:compile
+- commons-logging:commons-logging:jar:1.1.1:compile
+- org.aspectj:aspectjrt:jar:1.7.1:compile
+- org.aspectj:aspectjweaver:jar:1.7.1:compile
+- log4j:log4j:jar:1.2.17:compile
+- javax.servlet:jstl:jar:1.2:compile
+- cglib:cglib:jar:2.2.2:compile
|  \- asm:asm:jar:3.3.1:compile
+- org.slf4j:slf4j-log4j12:jar:1.7.2:compile
+- org.slf4j:slf4j-api:jar:1.7.2:compile
+- junit:junit:jar:4.10:compile
|  \- org.hamcrest:hamcrest-core:jar:1.1:compile
+- org.dbunit:dbunit:jar:2.4.9:test
|  \- commons-collections:commons-collections:jar:3.2.1:test
+- org.apache.derby:derby:jar:10.9.1.0:compile
+- org.springframework:spring-test:jar:3.1.3.RELEASE:test
+- org.seleniumhq.selenium:selenium-java:jar:2.26.0:test
|  +- org.seleniumhq.selenium:selenium-android-driver:jar:2.26.0:test
|  \- org.seleniumhq.selenium:selenium-remote-driver:jar:2.26.0:test
|  |     +- cglib:cglib-nodep:jar:2.1_3:test
|  |     +- org.json:json:jar:20080701:test
|  |     \- com.google.guava:guava:jar:13.0.1:test
|  +- org.seleniumhq.selenium:selenium-chrome-driver:jar:2.26.0:test
|  +- org.seleniumhq.selenium:selenium-htmlunit-driver:jar:2.26.0:test
|  |  +- org.seleniumhq.selenium:selenium-api:jar:2.26.0:test
|  |  +- net.sourceforge.htmlunit:htmlunit:jar:2.10:test
|  |  |  +- xalan:xalan:jar:2.7.1:test
|  |  |  |  \- xalan:serializer:jar:2.7.1:test
|  |  |  +- org.apache.commons:commons-lang3:jar:3.1:test
|  |  |  +- org.apache.httpcomponents:httpmime:jar:4.2.1:test
|  |  |  +- commons-codec:commons-codec:jar:1.6:test
|  |  |  +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.10:test
|  |  |  +- xerces:xercesImpl:jar:2.9.1:test
|  |  |  |  \- xml-apis:xml-apis:jar:1.3.04:test
|  |  |  +- net.sourceforge.nekohtml:nekohtml:jar:1.9.16:test
|  |  |  \- net.sourceforge.cssparser:cssparser:jar:0.9.7:test
|  |  |     \- org.w3c.css:sac:jar:1.3:test
|  |  \- org.apache.httpcomponents:httpclient:jar:4.2.1:test
|  |     \- org.apache.httpcomponents:httpcore:jar:4.2.1:test
|  +- org.seleniumhq.selenium:selenium-firefox-driver:jar:2.26.0:test
|  |  +- commons-io:commons-io:jar:2.2:test
|  |  \- org.apache.commons:commons-exec:jar:1.1:test
|  +- org.seleniumhq.selenium:selenium-ie-driver:jar:2.26.0:test
|  |  +- net.java.dev.jna:jna:jar:3.4.0:test
|  |  \- net.java.dev.jna:platform:jar:3.4.0:test
|  +- org.seleniumhq.selenium:selenium-iphone-driver:jar:2.26.0:test
|  +- org.seleniumhq.selenium:selenium-safari-driver:jar:2.26.0:test
|  +- org.seleniumhq.selenium:selenium-support:jar:2.26.0:test
|  \- org.webbitserver:webbit:jar:0.4.14:test
|     \- io.netty:netty:jar:3.5.2.Final:test

问题是 Hibernate 对 jboss-logging.jar 的依赖。当我将它部署到 JBoss 5.1.2 Enterprise Server 时,我收到以下错误:

Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.springframework.validation.beanvalidation.MethodValidationPostProcessor#0' defined in ServletContext resource [/WEB-INF/classes/spring/servlet-context.xml]: Cannot resolve reference to bean 'validator' while setting bean property 'validator'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'validator' defined in ServletContext resource [/WEB-INF/classes/spring/application-context.xml]: Error setting property values; nested exception is org.springframework.beans.PropertyBatchUpdateException; nested PropertyAccessExceptions (1) are: PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'validationMessageSource' threw exception; nested exception is java.lang.NoSuchMethodError: org.jboss.logmanager.LogContext.getAttachment(Ljava/lang/String;Lorg/jboss/logmanager/Logger$AttachmentKeyLjava/lang/Object; at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:329)

显然 jboss-logging.jar 和 EAP 服务器有些不兼容。我尝试从 Hibernate 依赖项中排除该 jar,但随后遇到此错误:

Caused by: java.lang.ClassNotFoundException: org.jboss.logging.BasicLogger at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:247) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:247) at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:311) at org.jboss.classloader.spi.base.BaseClassLoaderDomain.loadClass(BaseClassLoaderDomain.java:1163) at org.jboss.classloader.spi.base.BaseClassLoader.loadClassFromDomain(BaseClassLoader.java:862) at org.jboss.classloader.spi.base.BaseClassLoader.doLoadClass(BaseClassLoader.java:502) at org.jboss.classloader.spi.base.BaseClassLoader.loadClass(BaseClassLoader.java:447) at java.lang.ClassLoader.loadClass(ClassLoader.java:247)

我没有找到太多告诉我如何解决这个依赖问题的东西,所以我希望有人知道如何去做。

谢谢!

4

1 回答 1

5

好吧,在与同事合作时,我们找到了解决 JBoss 和 Hibernate 4 所遇到问题的解决方法。如果我们明确告诉 JBoss EAP 我们的日志实现(-D org.jboss.logging.provider=slf4j) ,它不会扫描日志实现,也没有我看到的 NoSuchMethod 异常。因此,除了设置一个系统属性外,我们无需进行任何其他更改。

于 2012-12-17T16:31:23.113 回答