NoSuchMethodError:org.jboss.logging.Logger.debugf

时间:2015-10-02 17:36:40

标签: spring spring-data glassfish-4.1 jboss-logging

我正在尝试使用Spring + Spring Data + Log4J2堆栈。 不幸的是,在My Glassfish 4.1 Server上部署人工制品时,会发生以下错误:


org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class com.canal.config.spring.ContextConfig: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.persistence.EntityManagerFactory com.canal.config.spring.ContextConfig.entityManagerFactory()] threw exception; nested exception is java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:601)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1113)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1008)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:505)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:229)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:725)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:757)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:480)
    at org.springframework.web.servlet.FrameworkServlet.configureAndRefreshWebApplicationContext(FrameworkServlet.java:663)
    at org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:535)
    at org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:489)
    at org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
    at javax.servlet.GenericServlet.init(GenericServlet.java:244)
    at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1382)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5704)
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:5946)
    at com.sun.enterprise.web.WebModule.start(WebModule.java:691)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:1041)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:1024)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:747)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2286)
    at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1932)
    at com.sun.enterprise.web.WebApplication.start(WebApplication.java:139)
    at org.glassfish.internal.data.EngineRef.start(EngineRef.java:122)
Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public javax.persistence.EntityManagerFactory com.canal.config.spring.ContextConfig.entityManagerFactory()] threw exception; nested exception is java.lang.NoSuchMethodError: org.jboss.logging.Logger.debugf(Ljava/lang/String;I)V
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:188)
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:590)
    ... 69 more
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.(SessionFactoryImpl.java:495)
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:802)
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60)
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343)
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318)
    at com.canal.config.spring.ContextConfig.entityManagerFactory(ContextConfig.java:52)
    at com.canal.config.spring.ContextConfig$$EnhancerBySpringCGLIB$$db0b8696.CGLIB$entityManagerFactory$0()
    at com.canal.config.spring.ContextConfig$$EnhancerBySpringCGLIB$$db0b8696$$FastClassBySpringCGLIB$$bca83b68.invoke()
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:312)
    at com.canal.config.spring.ContextConfig$$EnhancerBySpringCGLIB$$db0b8696.entityManagerFactory()
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:166)
    ... 70 more

我的pom.xml是:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.springapp</groupId>
    <artifactId>advance</artifactId>
    <packaging>war</packaging>
    <version>1.0-SNAPSHOT</version>
    <name>advance</name>

    <properties>
        <java.version>1.8</java.version>
        <springframework.version>4.2.1.RELEASE</springframework.version>
        <log4j.version>2.4</log4j.version>
        <javaee.version>7.0</javaee.version>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${springframework.version}</version>
            <exclusions>
                <!-- Utilise Log4J à la place du logger par défaut -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${springframework.version}</version>
            <exclusions>
                <!-- Utilise Log4J à la place du logger par défaut -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${springframework.version}</version>
            <exclusions>
                <!-- Utilise Log4J à la place du logger par défaut -->
                <exclusion>
                    <groupId>commons-logging</groupId>
                    <artifactId>commons-logging</artifactId>
                </exclusion>
            </exclusions>
        </dependency>

        <!-- Log4J2 Dependance -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-api</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>2.4</version>
        </dependency>
        <!-- Bridge Log Spring vers Log4J -->
        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-jcl</artifactId>
            <version>${log4j.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-tx</artifactId>
            <version>3.2.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-jdbc</artifactId>
            <version>3.2.8.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.data</groupId>
            <artifactId>spring-data-jpa</artifactId>
            <version>1.9.0.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>${javaee.version}</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>5.0.1.Final</version>
        </dependency>


    </dependencies>

    <build>
        <finalName>${artifactId}</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>${java.version}</source>
                    <target>${java.version}</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

有没有人有线索?

6 个答案:

答案 0 :(得分:6)

hibernate-entitymanager将jboss-logging作为依赖项引入,但它不是最新版本,并且没有实现该方法。看起来您不需要jboss-logging,所以请尝试将其排除:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-entitymanager</artifactId>
    <version>5.0.1.Final</version>
    <exclusions>
        <exclusion>
            <groupId>org.jboss.logging</groupId>
            <artifactId>jboss-logging</artifactId>
        </exclusion>
    </exclusions>
</dependency>

或者如果事实证明你需要jboss-logging用于hibernate,那么添加更高版本的jboss-logging作为额外的依赖。

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

答案 1 :(得分:6)

方法org.jboss.logging.Logger.debugf仅在jboss-logging版本3.3.0中可用,如果您在项目中具有此依赖项,则还必须检查您的GlassFish服务器是否也具有相同的版本。我有相同的错误消息,我解决了它取代glassfish安装文件夹中的jboss-logging.jar,因为这个jar是以前的版本,它没有所需的方法。例如,我在以下路径中有jar:

C:\Program Files\glassfish-4.1.1\glassfish\modules\jboss-logging.jar

我删除了旧jar,我把新jar用同名但版本3.3.0。只需重新启动GlassFish服务器,就可以使用新的jar版本。

答案 2 :(得分:6)

我有类似的问题,我可以通过在glassfish-web.xml目录中创建WEB-INF文件来修复它。该文件的内容如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish-web-app_3_0-1.dtd">
<glassfish-web-app>
     <class-loader delegate="false"/>
</glassfish-web-app>

这确保了glassfish不会加载它的内部库,而是加载项目中的库。

答案 3 :(得分:2)

这个问题是由JBoss模块jar中的冲突引起的。用最新版本替换文件jboss-logging解决了我的问题。该文件位于文件夹modules\system\layers\base\org\jboss\logging\main

此外,您应该使用新的jar名称替换文件module.xml中的jar名称。该文件位于同一文件夹中。

答案 4 :(得分:1)

我发现本文中的步骤对解决错误非常有用。 http://sanjayingole.blogspot.in/2015/10/caused-by-javalangnosuchmethoderror.html

简而言之的步骤(如果使用Eclipse) -

  1. 检查 ALL&#34; jboss-logging&#34;

    中的依赖关系层次结构中的子依赖关系,并排除所有这些依赖关系。

     <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>
    
  2. 使用具有该方法的jboss-logging版本。正如链接上所建议的那样,3.2.0.Final确实如此。

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

答案 5 :(得分:1)

如果您正在使用glassfish jersey,那么bean-validator将作为依赖项,而tomcat肯定会尝试从那里加载Logger类。

bean-validator clas在同一个包中也包含Logger类。

排除jar应解决问题

/* MovePlane
 * Moves plane to the right, down, left, up, and repeats using Timer object
 */

import java.awt.event.*;
import java.awt.*;
import javax.swing.*;


public class MovePlane extends JPanel implements ActionListener {
   private int delay = 5;
   private Timer timer;

   private int x = 10;      // x position
   private int y = 10;      // y position

   private boolean right = true;
   private boolean up = true;

   public MovePlane() {
       timer = new Timer(delay, this);
       timer.start();       // start the timer - infinite
   }

   public void actionPerformed(ActionEvent e) {
    // will run when the timer fires
       repaint();
   }

   public void paintComponent(Graphics g) {
       // both paint and paintComponent work - difference?
       super.paintComponent(g);    // call superclass's paintComponent 
       g.drawLine(x,y,x+20,y);               // body - drawn in terms of x
       g.drawLine(x+15,y-5,x+15,y+5);    // wing
       g.drawLine(x,y-2,x,y+2);  
       if (right && up) {
            x++;
            if (x == getWidth()-25) {
                right = false;
                up = false;
            }
       } else if (!right && !up) {
            y++;
            if (y == getHeight()-10) {
                up = true;
            }
       } else {
            if (x <= getWidth()-15 && x > 0) {
                x--;
            }
            if (x == 0) {
                y--;
            }
            if (y == 10) {
                right = true;
            }
       }
    }

    public static void main(String args[]) {
        JFrame frame = new JFrame("Move Plane");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        MovePlane bp = new MovePlane(); 
        frame.add(bp);
        frame.setSize(300, 300); // set frame size
        frame.setVisible(true); // display frame
    }

}