休眠 5 java.lang.NoSuchMethodError org.jboss.logging.Logger.debugf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31547015/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 11:14:03  来源:igfitidea点击:

Hibernate 5 java.lang.NoSuchMethodError org.jboss.logging.Logger.debugf

javaloggingjbosshibernate-5.x

提问by Jago Satori

I have a problem when I deploy a webapp with hibernate 5

我在使用 hibernate 5 部署 webapp 时遇到问题

Caused by: java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V
at org.hibernate.internal.NamedQueryRepository.checkNamedQueries(NamedQueryRepository.java:149) [hibernate-core-5.0.0.CR2.jar:5.0.0.CR2]
at org.hibernate.internal.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:759) [hibernate-core-5.0.0.CR2.jar:5.0.0.CR2]
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:490) [hibernate-core-5.0.0.CR2.jar:5.0.0.CR2]
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) [hibernate-core-5.0.0.CR2.jar:5.0.0.CR2]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708) [hibernate-core-5.0.0.CR2.jar:5.0.0.CR2]
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724) [hibernate-core-5.0.0.CR2.jar:5.0.0.CR2]
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:372) [spring-orm-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:454) [spring-orm-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:439) [spring-orm-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1633) [spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1570) [spring-beans-4.1.7.RELEASE.jar:4.1.7.RELEASE]
... 23 more

With Hibernate 4 everything is OK.

使用 Hibernate 4 一切正常。

I had a look at the class NamedQueryRepositoryat line 149. That class is calling the method debugf in this way

我查看了第NamedQueryRepository149 行的类。该类以这种方式调用方法 debugf

        log.debugf( "Checking %s named HQL queries", namedQueryDefinitionMap.size() );

I can not see the problem

我看不到问题

Here is my dependency tree

这是我的依赖树

[INFO] ------------------------------------------------------------------------
[INFO] Building app Maven Webapp 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ app---
[INFO] +- org.springframework:spring-aspects:jar:4.1.7.RELEASE:compile
[INFO] |  \- org.aspectj:aspectjweaver:jar:1.8.6:compile
[INFO] +- org.springframework:spring-tx:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework:spring-beans:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework:spring-context-support:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:4.1.7.RELEASE:compile
[INFO] |  \- org.springframework:spring-expression:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:4.1.7.RELEASE:compile
[INFO] |  \- commons-logging:commons-logging:jar:1.2:compile
[INFO] +- org.springframework:spring-orm:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:4.1.7.RELEASE:compile
[INFO] |  \- aopalliance:aopalliance:jar:1.0:compile
[INFO] +- org.springframework:spring-jdbc:jar:4.1.7.RELEASE:compile
[INFO] +- org.springframework:spring-test:jar:4.1.7.RELEASE:test
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.hibernate:hibernate-entitymanager:jar:5.0.0.CR2:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] |  +- org.hibernate:hibernate-core:jar:5.0.0.CR2:compile
[INFO] |  |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  |  \- org.jboss:jandex:jar:1.2.2.Final:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  |  \- xml-apis:xml-apis:jar:1.0.b2:compile
[INFO] |  +- org.hibernate.common:hibernate-commons-annotations:jar:5.0.0.Final:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
[INFO] |  \- org.javassist:javassist:jar:3.18.1-GA:compile
[INFO] +- org.hibernate:hibernate-c3p0:jar:5.0.0.CR2:compile
[INFO] |  \- com.mchange:c3p0:jar:0.9.2.1:compile
[INFO] |     \- com.mchange:mchange-commons-java:jar:0.2.3.4:compile
[INFO] +- org.primefaces:primefaces:jar:5.2.RC3:compile
[INFO] +- org.apache.logging.log4j:log4j-api:jar:2.2:compile
[INFO] +- org.apache.logging.log4j:log4j-core:jar:2.2:compile
[INFO] \- net.sourceforge.jtds:jtds:jar:1.2.8:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------

回答by David Levesque

Try upgrading jboss-logging.jarto a more recent version. The one you are using does not seem to be compatible with Hibernate 5.

尝试升级jboss-logging.jar到更新的版本。您使用的似乎与 Hibernate 5 不兼容。

回答by Marko Topolnik

In all probability you've got an outdated JBoss Logging JAR on the application's classpath. The ...fmethods are a relatively new addition to the Logger API. Hibernate 5 directly depends on Logging version 3.3.0, but it is possible that somehwere in your pom.xmlyou have an overriding dependency to an earlier version. Another possibility is that you are deploying to a JBoss container where the logging API is container-provided. Then you may need to upgrade the JBoss server, or introduce a workaround to prefer classes contributed by your application.

很可能您在应用程序的类路径上有一个过时的 JBoss Logging JAR。这些...f方法是对 Logger API 的一个相对较新的补充。Hibernate 5 直接依赖于 Logging 3.3.0 版,但您可能pom.xml对早期版本具有压倒性的依赖性。另一种可能性是您正在部署到 JBoss 容器,其中日志 API 是容器提供的。然后,您可能需要升级 JBoss 服务器,或引入一种变通方法来首选应用程序提供的类。

回答by Daniel Nitzan

In my case the culprit was the Jersey bean validator artifact. One of its dependencies, bean-validation-2.4.0-b06.jar contains Jboss logging classes, for some reason. I had to exclude the jersey-bean-validation and bean-validator artifacts from the spring-boot-starter-jersey dependency:

就我而言,罪魁祸首是 Jersey bean 验证器工件。由于某种原因,它的依赖项之一 bean-validation-2.4.0-b06.jar 包含 Jboss 日志记录类。我不得不从 spring-boot-starter-jersey 依赖项中排除 jersey-bean-validation 和 bean-validator 工件:

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-jersey</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>jersey-bean-validation</artifactId>
                <groupId>org.glassfish.jersey.ext</groupId>
            </exclusion>
            <exclusion>
                <artifactId>bean-validator</artifactId>
                <groupId>org.glassfish.hk2.external</groupId>
            </exclusion>
        </exclusions>
    </dependency>

EDIT: As of spring-boot 1.3.0, this is fixed and the exclusions above are not necessary anymore.

编辑:从 spring-boot 1.3.0 开始,此问题已修复,不再需要上述排除项。

回答by Ekrem Kucuk

In glass fish This problem is caused by collision with dependencies of glassfish modules. If you check lib list in glassfishdir/modules you would see boss-logging.jar. You can delete it and replace with latest such as org.jboss.logging:jboss-logging:jar:3.3.0.Final. It worked for me.

在 glassfish 此问题是由与 glassfish 模块的依赖项冲突引起的。如果您检查 glassfishdir/modules 中的 lib 列表,您将看到 boss-logging.jar。您可以将其删除并替换为最新的,例如 org.jboss.logging:jboss-logging:jar:3.3.0.Final。它对我有用。

回答by himangshuj

I too faced this issue. This is what fixed it for me

我也遇到过这个问题。这就是为我修复它的原因

       <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>4.2.1.RELEASE</version>
            <exclusions>
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

回答by Sudhir Kumar

I was getting the same error using jersey-spring-3 and hibernate 5.0.1.Final.Excluding org.glassfish.hk2.external:bean-validator from jersy-spring-3 and adding org.glassfish.jersey.ext:jersey-bean-validation worked for me.Here is my final dependency.

我在使用 jersey-spring-3 和 hibernate 5.0.1.Final.Exducing org.glassfish.hk2.external:bean-validator from jersy-spring-3 并添加 org.glassfish.jersey.ext:jersey- 时遇到了同样的错误bean 验证对我有用。这是我的最终依赖项。

<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-spring3</artifactId>
    <version>2.22.2</version>
    <exclusions>
        <exclusion>
            <groupId>org.glassfish.hk2.external</groupId>
            <artifactId>bean-validator</artifactId>
        </exclusion>
    </exclusions>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-bean-validation</artifactId>
    <version>2.22.2</version>
</dependency>

from :

从 :

<dependency>
    <groupId>org.glassfish.jersey.ext</groupId>
    <artifactId>jersey-spring3</artifactId>
    <version>2.22.2</version>
</dependency>

回答by Evgeniy

I also faced with such kind of problem when deployed ear on weblogic server. Apparently, weblogic also use jboss logging system, and use old version of it.
My fix:
Add "weblogic-application.xml" to META-INF folder with this content:

在 weblogic 服务器上部署 ear 时,我也遇到了这种问题。显然,weblogic 也使用 jboss 日志系统,并且使用它的旧版本。
我的修复:
将“weblogic-application.xml”添加到具有以下内容的 META-INF 文件夹中:

    <?xml version="1.0" encoding="UTF-8"?>
    <weblogic-application>
        <prefer-application-packages>
            <package-name>org.jboss.logging.*</package-name>
        </prefer-application-packages>

        <prefer-application-resources>
            <resource-name>org/jboss/logging/Logger.class</resource-name>
        </prefer-application-resources>
    </weblogic-application>

回答by RJ.Hwang

I have the same problen with spring4.2.1+hibernate5.0.2+jersey2.23.1. My solution is the same: Excluding org.glassfish.hk2.external:bean-validatorfrom jersy-spring-3and adding org.glassfish.jersey.ext:jersey-bean-validation.

我对 spring4.2.1+hibernate5.0.2+jersey2.23.1 有同样的问题。我的解决办法是一样的:不包括org.glassfish.hk2.external:bean-validatorjersy-spring-3和添加org.glassfish.jersey.ext:jersey-bean-validation

<dependency>
  <groupId>org.glassfish.jersey.ext</groupId>
  <artifactId>jersey-spring3</artifactId>
  <version>2.23.1</version>
  <exclusions>
    <exclusion>
      <groupId>org.glassfish.hk2.external</groupId>
      <artifactId>bean-validator</artifactId>
    </exclusion>
  </exclusions>
</dependency>
<dependency>
  <groupId>org.glassfish.jersey.ext</groupId>
  <artifactId>jersey-bean-validation</artifactId>
  <version>2.23.1</version>
</dependency>

In my product environment, just delete bean-validator-2.4.0-b34.jarand add jersey-bean-validation-2.23.1.jar

在我的产品环境中,删除bean-validator-2.4.0-b34.jar添加即可jersey-bean-validation-2.23.1.jar

回答by Karl Richter

This can be caused if a dependency includes

如果依赖项包括

<dependency>
    <groupId>org.eclipse.persistence</groupId>
    <artifactId>eclipselink</artifactId>
    <version>2.6.2</version>
</dependency>

Exclude it using an exclusionselement in dependency.

使用 中的exclusions元素排除它dependency

回答by Keshav

Check my answer at NoSuchMethodError: org.jboss.logging.Logger.debugf

NoSuchMethodError处检查我的答案:org.jboss.logging.Logger.debugf

Even I was having issues after upgrading to Hibernate 5.2 , and the culprit was "jboss-logging 3.3.0.Final" which I see present in your dependencies too. Following the steps on the link shared in the answer, you can reduce the dependency jboss-logging to 3.2 level which has the required function.

即使我在升级到 Hibernate 5.2 后也遇到了问题,罪魁祸首是“jboss-logging 3.3.0.Final”,我在您的依赖项中也看到了它。按照答案中共享的链接上的步骤,您可以将依赖 jboss-logging 减少到具有所需功能的 3.2 级别。