Monday, October 19, 2015

Caused by: java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V

Getting following exception while trying to build a hibernate Spring web application on tomcat.

Following is the Exception :

Caused by: java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V
at org.hibernate.internal.NamedQueryRepository.checkNamedQueries(NamedQueryRepository.java:149)
at org.hibernate.internal.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:764)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:495)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:708)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:724)
at org.springframework.orm.hibernate4.LocalSessionFactoryBuilder.buildSessionFactory(LocalSessionFactoryBuilder.java:372)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:454)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:439)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)

... 21 more

Solution:

Checked for the dependency hierarchy in pom.xml


Added the exclusion to hibernate-entitymanager dependency:

<dependency>
             <groupId>org.hibernate</groupId>
             <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate.version}</version>
            <exclusions>           
                <exclusion>
                    <artifactId>jboss-logging</artifactId>
                    <groupId>org.jboss.logging</groupId>
                </exclusion>
            </exclusions>

         </dependency>


You might get following after adding exclusion :

Caused by: java.lang.NoClassDefFoundError: org/jboss/logging/BasicLogger
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2944)
at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1208)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1688)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569)
at org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:28)
at org.hibernate.internal.CoreLogging.messageLogger(CoreLogging.java:24)
at org.hibernate.cfg.Configuration.<clinit>(Configuration.java:86)
at org.springframework.orm.hibernate4.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:343)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)
... 21 more
Caused by: java.lang.ClassNotFoundException: org.jboss.logging.BasicLogger
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1718)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1569)
... 34 more

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed


Try adding the following dependency in pom :

<dependency>
           <artifactId>jboss-logging</artifactId>
           <groupId>org.jboss.logging</groupId>            
           <version>3.2.0.Final</version>
</dependency>

4 comments:

  1. I've done as you wrote, but it still doesn't work(

    ReplyDelete
    Replies
    1. Could you please share the details as to what's your spring and hibernate version and are you using tomat or any other server. Are you getting the same error as mentioned in the logs above.

      Delete
  2. at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_51]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_51]
    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.12.Final.jar:5.0.12.Final]
    at org.hibernate.internal.SessionFactoryImpl.checkNamedQueries(SessionFactoryImpl.java:771) [hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.internal.SessionFactoryImpl.(SessionFactoryImpl.java:486) [hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) [hibernate-core-5.0.12.Final.jar:5.0.12.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879) [hibernate-entitymanager-5.0.12.Final.jar:5.0.12.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) [spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:353) [spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.buildNativeEntityManagerFactory(AbstractEntityManagerFactoryBean.java:370) [spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:359) [spring-orm-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) [spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
    ... 25 more

    ReplyDelete
    Replies
    1. I tried configuration given in post. But still didn't work for me. I am trying to deploy war on Wildfly 8. Here is my configuration file pom.xml



      4.0.0
      com.hello
      hello
      0.0.1-SNAPSHOT
      war

      hello
      hello for Inventory Management


      org.springframework.boot
      spring-boot-starter-parent
      1.5.6.RELEASE




      UTF-8
      UTF-8
      1.8
      1.1.9





      org.springframework.boot
      spring-boot-starter-data-jpa



      org.hibernate
      hibernate-entitymanager


      jboss-logging
      org.jboss.logging




      jboss-logging
      org.jboss.logging
      3.2.0.Final



      org.springframework.boot
      spring-boot-starter-security




      org.springframework.security
      spring-security-core


      org.springframework.security
      spring-security-config


      org.springframework.security
      spring-security-web


      org.springframework.security
      spring-security-taglibs




      javax.servlet
      javax.servlet-api
      provided




      org.springframework.boot
      spring-boot-starter-web


      org.springframework.boot
      spring-boot-starter-tomcat




      org.springframework.boot
      spring-boot-starter-undertow
      provided



      mysql
      mysql-connector-java
      runtime




      org.springframework.boot
      spring-boot-starter-test
      test




      org.springframework.boot
      spring-boot-devtools
      true




      net.sourceforge.nekohtml
      nekohtml
      1.9.21



      javax.servlet
      jstl




      org.apache.tomcat.embed
      tomcat-embed-jasper
      provided




      org.eclipse.jdt.core.compiler
      ecj
      4.6.1
      provided




      org.webjars
      bootstrap
      3.3.7





      com.google.guava
      guava
      12.0-rc2






      org.springframework.boot
      spring-boot-maven-plugin






      Delete