将spring与hibernate 5集成时的异常

时间:2016-12-05 06:48:46

标签: spring hibernate hibernate-5.x

这是我的依赖树

[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building web Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ web ---
[INFO] com.crazyuni:web:war:0.0.1-SNAPSHOT
[INFO] +- junit:junit:jar:4.12:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.3:test
[INFO] +- org.springframework:spring-test:jar:4.3.4.RELEASE:test
[INFO] +- javax.servlet:servlet-api:jar:2.5:provided
[INFO] +- commons-fileupload:commons-fileupload:jar:1.3.1:compile
[INFO] +- commons-io:commons-io:jar:2.2:compile
[INFO] +- commons-lang:commons-lang:jar:2.4:compile
[INFO] +- commons-logging:commons-logging:jar:1.1.3:compile
[INFO] +- commons-logging:commons-logging-api:jar:1.1:compile
[INFO] +- org.freemarker:freemarker:jar:2.3.22:compile
[INFO] +- org.javassist:javassist:jar:3.19.0-GA:compile
[INFO] +- ognl:ognl:jar:3.0.6:compile
[INFO] |  \- javassist:javassist:jar:3.11.0.GA:compile
[INFO] +- org.apache.struts:struts2-core:jar:2.3.24:compile
[INFO] +- org.apache.struts.xwork:xwork-core:jar:2.3.24:compile
[INFO] |  +- org.apache.commons:commons-lang3:jar:3.2:compile
[INFO] |  +- asm:asm:jar:3.3:compile
[INFO] |  \- asm:asm-commons:jar:3.3:compile
[INFO] |     \- asm:asm-tree:jar:3.3:compile
[INFO] +- org.apache.struts:struts2-json-plugin:jar:2.3.24:compile
[INFO] +- org.springframework:spring-beans:jar:4.3.4.RELEASE:compile
[INFO] +- org.springframework:spring-context:jar:4.3.4.RELEASE:compile
[INFO] +- org.springframework:spring-core:jar:4.3.4.RELEASE:compile
[INFO] +- org.springframework:spring-expression:jar:4.3.4.RELEASE:compile
[INFO] +- org.springframework:spring-web:jar:4.3.4.RELEASE:compile
[INFO] +- org.springframework:spring-aop:jar:4.3.4.RELEASE:compile
[INFO] +- org.springframework:spring-orm:jar:4.3.4.RELEASE:compile
[INFO] |  \- org.springframework:spring-tx:jar:4.3.4.RELEASE:compile
[INFO] +- org.springframework:spring-jdbc:jar:4.3.4.RELEASE:compile
[INFO] +- org.apache.struts:struts2-spring-plugin:jar:2.3.24:compile
[INFO] +- org.apache.tiles:tiles-api:jar:2.0.6:compile
[INFO] +- org.apache.tiles:tiles-compat:jar:3.0.1:compile
[INFO] +- org.apache.tiles:tiles-core:jar:2.0.6:compile
[INFO] +- org.apache.tiles:tiles-jsp:jar:2.0.6:compile
[INFO] +- org.apache.tiles:tiles-servlet:jar:3.0.1:compile
[INFO] |  \- org.apache.tiles:tiles-request-servlet:jar:1.0.1:compile
[INFO] |     \- org.apache.tiles:tiles-request-api:jar:1.0.1:compile
[INFO] +- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] +- commons-digester:commons-digester:jar:2.0:compile
[INFO] +- org.apache.struts:struts2-tiles-plugin:jar:2.3.24:compile
[INFO] +- org.hibernate:hibernate-core:jar:5.2.5.Final:compile
[INFO] |  +- org.jboss.logging:jboss-logging:jar:3.3.0.Final:compile
[INFO] |  +- org.hibernate.javax.persistence:hibernate-jpa-2.1-api:jar:1.0.0.Final:compile
[INFO] |  +- antlr:antlr:jar:2.7.7:compile
[INFO] |  +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile
[INFO] |  +- org.jboss:jandex:jar:2.0.3.Final:compile
[INFO] |  +- com.fasterxml:classmate:jar:1.3.0:compile
[INFO] |  +- dom4j:dom4j:jar:1.6.1:compile
[INFO] |  +- org.hibernate.common:hibernate-commons-annotations:jar:5.0.1.Final:compile
[INFO] |  \- javax.enterprise:cdi-api:jar:1.1:compile
[INFO] |     +- org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.1_spec:jar:1.0.0.Beta1:compile
[INFO] |     +- javax.annotation:jsr250-api:jar:1.0:compile
[INFO] |     \- javax.inject:javax.inject:jar:1:compile
[INFO] +- org.hibernate:hibernate-java8:jar:5.2.5.Final:compile
[INFO] +- mysql:mysql-connector-java:jar:5.1.27:compile
[INFO] +- commons-codec:commons-codec:jar:1.10:compile
[INFO] +- log4j:log4j:jar:1.2.17:compile
[INFO] +- org.quartz-scheduler:quartz:jar:2.2.1:compile
[INFO] |  +- c3p0:c3p0:jar:0.9.1.1:compile
[INFO] |  \- org.slf4j:slf4j-api:jar:1.6.6:compile
[INFO] +- org.quartz-scheduler:quartz-jobs:jar:2.2.1:compile
[INFO] +- javax.mail:mail:jar:1.4:compile
[INFO] |  \- javax.activation:activation:jar:1.1:compile
[INFO] +- com.googlecode.json-simple:json-simple:jar:1.1.1:compile
[INFO] +- com.restfb:restfb:jar:1.15.0:compile
[INFO] +- org.ocpsoft.prettytime:prettytime:jar:3.2.7.Final:compile
[INFO] +- displaytag:displaytag:jar:1.2:compile
[INFO] |  +- commons-collections:commons-collections:jar:3.1:compile
[INFO] |  \- com.lowagie:itext:jar:1.3:compile
[INFO] +- cn.apiclub.tool:simplecaptcha:jar:1.2.2:compile
[INFO] +- com.github.scribejava:scribejava-apis:jar:2.0.1:compile
[INFO] +- com.github.scribejava:scribejava-core:jar:2.0.1:compile
[INFO] +- net.sf.jasperreports:jasperreports:jar:6.2.2:compile
[INFO] |  +- org.jfree:jcommon:jar:1.0.23:compile
[INFO] |  +- org.jfree:jfreechart:jar:1.0.19:compile
[INFO] |  +- org.eclipse.jdt.core.compiler:ecj:jar:4.3.1:compile
[INFO] |  +- org.codehaus.castor:castor-xml:jar:1.3.3:compile
[INFO] |  |  +- org.codehaus.castor:castor-core:jar:1.3.3:compile
[INFO] |  |  +- stax:stax:jar:1.2.0:compile
[INFO] |  |  |  \- stax:stax-api:jar:1.0.1:compile
[INFO] |  |  \- javax.xml.stream:stax-api:jar:1.0-2:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-core:jar:2.1.4:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-databind:jar:2.1.4:compile
[INFO] |  +- com.fasterxml.jackson.core:jackson-annotations:jar:2.1.4:compile
[INFO] |  +- org.apache.lucene:lucene-core:jar:4.5.1:compile
[INFO] |  +- org.apache.lucene:lucene-analyzers-common:jar:4.5.1:compile
[INFO] |  +- org.apache.lucene:lucene-queryparser:jar:4.5.1:compile
[INFO] |  |  +- org.apache.lucene:lucene-queries:jar:4.5.1:compile
[INFO] |  |  \- org.apache.lucene:lucene-sandbox:jar:4.5.1:compile
[INFO] |  |     \- jakarta-regexp:jakarta-regexp:jar:1.4:compile
[INFO] |  +- org.olap4j:olap4j:jar:0.9.7.309-JS-3:compile
[INFO] |  +- com.google.zxing:core:jar:2.3.0:compile
[INFO] |  \- com.ibm.icu:icu4j:jar:57.1:compile
[INFO] +- net.sf.jasperreports:jasperreports-fonts:jar:6.0.0:compile
[INFO] +- org.codehaus.groovy:groovy-all:jar:2.4.6:compile
[INFO] +- com.itextpdf:itextpdf:jar:5.5.6:compile
[INFO] \- com.h2database:h2:jar:1.4.193:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.774 s
[INFO] Finished at: 2016-12-05T13:38:23+07:00
[INFO] Final Memory: 19M/328M
[INFO] ------------------------------------------------------------------------

但是当我通过命令tomcat7运行tomcat7时运行:运行

它抛出以下异常,但我不知道为什么? althoght我仍然在类路径中看到类org.hibernate.cfg.Configuration

2016-12-05 13:36:54 ERROR ContextLoader:351 - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Failed to introspect bean class [org.springframework.orm.hibernate5.LocalSessionFactoryBean] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:269)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1073)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
    at com.edinnova.dashboard.context.MyApplicationContext.contextInitialized(MyApplicationContext.java:36)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.getDeclaredMethods(Class.java:1975)
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613)
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524)
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:247)
    ... 24 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
    ... 31 more
Dec 05, 2016 1:36:54 PM org.apache.catalina.core.StandardContext listenerStart
SEVERE: Exception sending context initialized event to listener instance of class com.edinnova.dashboard.context.MyApplicationContext
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Failed to introspect bean class [org.springframework.orm.hibernate5.LocalSessionFactoryBean] for lookup method metadata: could not find class that it depends on; nested exception is java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:269)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineConstructorsFromBeanPostProcessors(AbstractAutowireCapableBeanFactory.java:1073)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1046)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:512)
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482)
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306)
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:735)
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:866)
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:542)
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:444)
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:326)
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:107)
    at com.edinnova.dashboard.context.MyApplicationContext.contextInitialized(MyApplicationContext.java:36)
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4939)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5434)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1559)
    at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1549)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
    at java.lang.Class.getDeclaredMethods0(Native Method)
    at java.lang.Class.privateGetDeclaredMethods(Class.java:2701)
    at java.lang.Class.getDeclaredMethods(Class.java:1975)
    at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:613)
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:524)
    at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:510)
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.determineCandidateConstructors(AutowiredAnnotationBeanPostProcessor.java:247)
    ... 24 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
    ... 31 more

以及更多,这是我在项目中使用的spring bean配置:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.1.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
    <context:annotation-config />
    <bean id="dataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="org.h2.Driver" />
        <property name="url" value="jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1" />
        <property name="username" value="sa" />
        <property name="password" value="" />
    </bean>
    <bean id="sessionFactory"
        class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
        <property name="packagesToScan">
            <value>com.edinnova.dashboard.dao.entities</value>
        </property>
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
                <prop key="hibernate.show_sql">true</prop>
                <prop key="hibernate.connection.driver_class">org.h2.Driver</prop>
                <prop key="hibernate.connection.autocommit">false</prop>
                <prop key="hibernate.connection.release_mode">on_close</prop>
                <prop key="hibernate.format_sql">false</prop>
                <prop key="hibernate.connection.useUnicode">true</prop>
                <prop key="hibernate.connection.characterEncoding">UTF-8</prop>
                <prop key="hibernate.connection.charSet">UTF-8</prop>
                <prop key="hibernate.max_fetch_depth">2</prop>
                <prop key="hibernate.hbm2ddl.auto">create</prop>
            </props>
        </property>
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <bean id="repository" class="com.edinnova.dashboard.dao.repo.RepositoryImpl"
        scope="singleton" />
    <bean id="insertRepository"
        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
        <property name="transactionManager">
            <ref local="transactionManager" />
        </property>
        <property name="target">
            <bean class="com.edinnova.dashboard.dao.repo.InsertRepositoryImpl">
                <constructor-arg ref="sessionFactory" />
            </bean>
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="*">PROPAGATION_REQUIRED</prop>
            </props>
        </property>
    </bean>
    <bean id="selectRepository"
        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
        <property name="transactionManager">
            <ref local="transactionManager" />
        </property>
        <property name="target">
            <bean class="com.edinnova.dashboard.dao.repo.SelectRepositoryImpl">
                <constructor-arg ref="sessionFactory" />
            </bean>
        </property>
        <property name="transactionAttributes">
            <props>
                <prop key="*">PROPAGATION_REQUIRED</prop>
            </props>
        </property>
    </bean>
    <bean id="transactionManager"
        class="org.springframework.orm.hibernate5.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    <tx:annotation-driven transaction-manager="transactionManager"></tx:annotation-driven>
</beans>

请帮助,我感谢优势!

0 个答案:

没有答案