java.lang.NoSuchMethodError:org.jboss.logging.Logger.debug Spring 4.3,Hibernate 5.1

时间:2016-06-15 02:50:12

标签: java spring hibernate maven jax-rs

我正拉着我头脑中的头发试图解决这个问题。我有两个项目,一个依赖另一个。

Project a pom.xml

<properties>
    <jersey.version>2.23.1</jersey.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<build>
    <finalName>ws2</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.5.1</version>
            <inherited>true</inherited>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey</groupId>
            <artifactId>jersey-bom</artifactId>
            <version>${jersey.version}</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

<dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <!-- use the following artifactId if you don't need servlet 2.x 
            compatibility -->
        <!-- artifactId>jersey-container-servlet</artifactId -->
    </dependency>

    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>6.0.2</version>
    </dependency>

    <dependency>
        <groupId>waterwingsdao</groupId>
        <artifactId>waterwingsdao</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>

    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.6.2</version>
    </dependency>

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

    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.2</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>4.3.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-beans</artifactId>
        <version>4.3.0.RELEASE</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-orm</artifactId>
        <version>4.3.0.RELEASE</version>
    </dependency>

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

Project A applicationContext.xml     

<bean id="sessionFactory"
    class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
    <property name="dataSource" ref="wwDbConfig" />
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
            <prop key="hibernate.current_session_context_class">thread</prop>
            <prop key="hibernate.show_sql">true</prop>
        </props>
    </property>
</bean>

<!-- JNDI config -->
<bean id="wwDbConfig" class="org.springframework.jndi.JndiObjectFactoryBean"
    scope="singleton">
    <property name="jndiName" value="java:comp/env/jdbc/blahblah" />
    <property name="resourceRef" value="true" />
</bean>

项目B(A取决于B)pom.xml

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <!-- <dependency> <groupId>org.hibernate</groupId> <artifactId>hibernate-core</artifactId> 
        <version>3.6.3.Final</version> </dependency> -->

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

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


    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>6.0.2</version>
    </dependency>

    <dependency>
        <groupId>org.javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.20.0-GA</version>
    </dependency>

    <dependency>
        <groupId>com.mchange</groupId>
        <artifactId>c3p0</artifactId>
        <version>0.9.5.2</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.7.21</version>
    </dependency>

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-context</artifactId>
        <version>4.3.0.RELEASE</version>
    </dependency>


</dependencies>

这是堆栈跟踪:

org.springframework.beans.factory.BeanCreationException:在类路径资源[applicationContext.xml]中定义名称为'sessionFactory'的bean时出错:init方法的调用失败;嵌套异常是java.lang.NoSuchMethodError:org.jboss.logging.Logger.debugf(Ljava / lang / String; I)V     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)     at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject(AbstractBeanFactory.java:306)     在org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)     在org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)     在org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)     在org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:756)     at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:861)     在org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:541)     at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:389)     在org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:294)     在org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:112)     在org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4813)     at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5272)     在org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:147)     在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1407)     在org.apache.catalina.core.ContainerBase $ StartChild.call(ContainerBase.java:1397)     at java.util.concurrent.FutureTask.run(FutureTask.java:266)     在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)     at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)     在java.lang.Thread.run(Thread.java:745) 引起:java.lang.NoSuchMethodError:org.jboss.logging.Logger.debugf(Ljava / lang / String; I)V     在org.hibernate.cfg.Settings。(Settings.java:81)     在org.hibernate.cfg.Settings。(Settings.java:50)     在org.hibernate.internal.SessionFactoryImpl。(SessionFactoryImpl.java:200)     在org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:476)     在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:707)     在org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:723)     在org.springframework.orm.hibernate5.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:504)     在org.springframework.orm.hibernate5.LocalSessionFactoryBean.afterPropertiesSet(LocalSessionFactoryBean.java:488)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637)     在org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574)

我的目的是在MySQL上使用hibernate构建一个Jax-RS服务,它全部加载了Spring。

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:3)

我找到了答案,Hibernate 5.1.0 Final依赖于JBoss Logging。我添加了

isql host:port dba pwd exec="set blobs on; sparql define output:format '"TURTLE"' construct {...} from <....> where {....}" > XX.ttl

我仍然需要以下排除:

tail -n +9 XX.ttl > XX_new.ttl

感谢您的帮助,有时您需要另一组眼睛或朝正确的方向轻推。

答案 1 :(得分:0)

看起来您正在尝试使用Commons Logging并排除jboss记录器。但其中一个类是使用jboss日志记录。从堆栈跟踪中找出调用jboss logger类的类。由于在运行时logger类不可用,因此应用程序抛出NoSuchMethodError。