2015-09-03 34 views
1

我試圖開發一個新的Spring Web應用程序,但我有一個配置的問題..如何解決Servlet上下文錯誤到Spring?

ERROR: org.springframework.web.context.ContextLoader - Context initialization failed 
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'emf' defined in ServletContext resource [/WEB-INF/spring/jpa-tx-config.xml]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1553) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:539) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195) 
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:973) 
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:750) 
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) 
    at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext(ContextLoader.java:403) 
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:306) 
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:106) 
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4729) 
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5167) 
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) 
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:725) 
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:701) 
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:717) 
    at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:586) 
    at org.apache.catalina.startup.HostConfig$DeployDescriptor.run(HostConfig.java:1750) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471) 
    at java.util.concurrent.FutureTask.run(FutureTask.java:262) 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) 
    at java.lang.Thread.run(Thread.java:745) 
Caused by: java.lang.AbstractMethodError 
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:278) 
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) 
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:802) 
    at org.hibernate.jpa.HibernatePersistenceProvider.createContainerEntityManagerFactory(HibernatePersistenceProvider.java:135) 
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:336) 
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) 
    ... 25 more 

這是我jpa-tx-config.xml

<?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:context="http://www.springframework.org/schema/context" 
    xmlns:jpa="http://www.springframework.org/schema/data/jpa" 
    xmlns:tx="http://www.springframework.org/schema/tx" 
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd 
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd 
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd 
    http://www.springframework.org/schema/data/jpa http://www.springframework.org/schema/data/jpa/spring-jpa.xsd 
    http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc.xsd"> 

    <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"> 
     <property name="entityManagerFactory" ref="emf"/> 
    </bean> 

    <tx:annotation-driven transaction-manager="transactionManager" /> 

    <bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"> 
     <property name="dataSource" ref="dataSource" /> 
     <property name="jpaVendorAdapter"> 
      <bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" /> 
     </property> 
     <property name="packagesToScan" value="my.domain"/> 

     <property name="persistenceUnitName" value="persistenceUnit"/> 
     <property name="jpaProperties"> 
      <props> 
       <prop key="hibernate.dialect">org.hibernate.dialect.MySQL5InnoDBDialect</prop> 
       <prop key="hibernate.hbm2ddl.auto">update</prop> 
       <prop key="hibernate.ejb.naming_strategy">org.hibernate.cfg.ImprovedNamingStrategy</prop> 
       <prop key="hibernate.connection.charSet">UTF-8</prop> 

       <prop key="hibernate.max_fetch_depth">3</prop> 
       <prop key="hibernate.jdbc.fetch_size">50</prop> 
       <prop key="hibernate.jdbc.batch_size">20</prop> 
       <prop key="hibernate.show_sql">false</prop> 
       <prop key="hibernate.format_sql">true</prop> 

       <prop key="org.hibernate.envers.audit_table_suffix">_H</prop> 
       <prop key="org.hibernate.envers.revision_field_name">AUDIT_REVISION</prop> 
       <prop key="org.hibernate.envers.revision_type_field_name">ACTION_TYPE</prop> 
       <prop key="org.hibernate.envers.audit_strategy">org.hibernate.envers.strategy.ValidityAuditStrategy</prop> 
       <prop key="org.hibernate.envers.audit_strategy_validity_end_rev_field_name">AUDIT_REVISION_END</prop> 
       <prop key="org.hibernate.envers.audit_strategy_validity_store_revend_timestamp">True</prop> 
       <prop key="org.hibernate.envers.audit_strategy_validity_revend_timestamp_field_name">AUDIT_REVISION_END_TS</prop>    
       <prop key="jadira.usertype.databaseZone">jvm</prop> 
      </props> 
     </property> 
    </bean> 

    <jpa:repositories base-package="my.repository" entity-manager-factory-ref="emf" 
     transaction-manager-ref="transactionManager"/> 

    <jpa:auditing auditor-aware-ref="auditorAwareBean" /> 

    <bean id="auditorAwareBean" class="it.cpmapave.ped.auditor.AuditorAwareBean"/> 

</beans> 

我認爲這是正確的..

我該如何解決?

編輯 添加一塊我的pom,也許可以幫助理解爲什麼。

這些都是我依賴的版本:

<jsp.version>2.2</jsp.version> 
<jstl.version>1.2</jstl.version> 
<servlet.version>2.5</servlet.version> 

<!-- Spring --> 
<org.springframework-version>4.0.2.RELEASE</org.springframework-version> 
<org.springsecurity-version>4.0.2.RELEASE</org.springsecurity-version> 
<spring-data-jpa.version>1.7.2.RELEASE</spring-data-jpa.version> 

<!-- Hibernate/JPA --> 
<hibernate.version>5.0.0.Final</hibernate.version> 
<hibernate.validator.version>5.0.0.Final</hibernate.validator.version> 

<!-- Jackson --> 
<jackson.version>2.2.2</jackson.version> 

<!-- QueryDSL --> 
<querydsl.version>3.3.2</querydsl.version> 
+1

你可以添加完整的堆棧跟蹤嗎? –

+0

@AtulRai是的!我將它添加:) – Droide

+0

「java.lang.AbstractMethodError at org.hibernate.internal.SessionFactoryImpl」。不能比這更清楚。不正確的Hibernate罐/依賴關係 –

回答

1

試圖改變自己的POM版本:

<org.springframework-version>4.1.6.RELEASE</org.springframework-version> 
    <org.springsecurity-version>4.0.2.RELEASE</org.springsecurity-version> 
    <spring-data-jpa.version>1.8.2.RELEASE</spring-data-jpa.version> 

    <hibernate.version>4.3.5.Final</hibernate.version> 
    <hibernate.validator.version>5.0.0.Final</hibernate.validator.version> 

我不明白爲什麼要降級冬眠它運行的版本..但我有同樣的問題,並用這種方法我沒有問題。