2013-04-08 93 views
3

我開始使用spring 3 hibernate 4的新技術,並且我嘗試從教程中執行以下示例。每次我得到相同的錯誤。我使用Spring 3.1.1 Hibernate 4.1.0。文件配置休眠4和彈簧3

<?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:aop="http://www.springframework.org/schema/aop" 
    xmlns:context="http://www.springframework.org/schema/context" 
    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/aop http://www.springframework.org/schema/aop/spring-aop-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/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd"> 

<!-- Data Source Declaration --> 
    <bean id="DataSource" class="org.apache.commons.dbcp.BasicDataSource" > 
     <property name="driverClassName" value="org.postgresql.Driver" /> 
     <property name="url" value="jdbc:postgresql:Bibliotheque" /> 
     <property name="username" value="postgres" /> 
     <property name="password" value="root" /> 

    </bean> 

    <!-- Session Factory Declaration --> 
    <bean id="SessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"> 
     <property name="dataSource" ref="DataSource" /> 
     <property name="annotatedClasses"> 
      <list> 
       <value>com.ardia.Adherent</value> 
       <value>com.ardia.Emprunt</value> 
       <value>com.ardia.Fournisseur</value> 
       <value>com.ardia.Livre</value> 
      </list> 
     </property> 
     <property name="hibernateProperties"> 
      <props> 
       <prop key="hibernate.dialect">org.hibernate.dialect.PostgreSQLDialect</prop> 
       <prop key="hibernate.show_sql">true</prop> 
      </props> 
     </property> 
    </bean> 
<!-- Transaction Manager is defined --> 
    <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
     <property name="sessionFactory" ref="SessionFactory"/> 
    </bean> 

<!-- Enable the configuration of transactional behavior based on annotations --> 

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

</beans> 

這是消息,我不明白:

時出錯處理XML '組織/ springframework的/交易/攔截器/ TransactionInterceptor'。看到錯誤日誌中的更多詳細信息

時出錯處理 '/Hibernate_spring/src/application_configuration.xml'

java.lang.NoClassDefFoundError: org/springframework/transaction/interceptor/TransactionInterceptor 
    at org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser$AopAutoProxyConfigurer.configureAutoProxyCreator(AnnotationDrivenBeanDefinitionParser.java:126) 
    at org.springframework.transaction.config.AnnotationDrivenBeanDefinitionParser.parse(AnnotationDrivenBeanDefinitionParser.java:84) 
    at org.springframework.beans.factory.xml.NamespaceHandlerSupport.parse(NamespaceHandlerSupport.java:73) 
    at org.springframework.ide.eclipse.beans.core.internal.model.namespaces.DelegatingNamespaceHandlerResolver$ElementTrackingNamespaceHandler.parse(DelegatingNamespaceHandlerResolver.java:177) 
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1335) 
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$ErrorSuppressingBeanDefinitionParserDelegate.parseCustomElement(BeansConfig.java:1292) 
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1325) 
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135) 
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:93) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:493) 
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.registerBeanDefinitions(BeansConfig.java:389) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:390) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334) 
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$2.loadBeanDefinitions(BeansConfig.java:375) 
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:302) 
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:421) 
    at org.springframework.ide.eclipse.beans.core.internal.model.BeansConfig$3.call(BeansConfig.java:1) 
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) 
    at java.util.concurrent.FutureTask.run(Unknown Source) 
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) 
    at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source) 
    at java.util.concurrent.FutureTask.run(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
    at java.lang.Thread.run(Unknown Source) 

回答

0

請確保您有彈簧tx.jar,彈簧orm.jar和休眠-的EntityManager .jar文件在您的類路徑上的適當版本。

同樣在您的配置中,請注意transactionManager未正確引用。

<!-- An id of txManager is assigned here --> 
    <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
     <property name="sessionFactory" ref="SessionFactory"/> 
    </bean> 

<!-- While transactionManager is referenced here -->  
<tx:annotation-driven transaction-manager="transactionManager"/> 

配置的這一行應該改變transaction-manager指向txManager豆:

<tx:annotation-driven transaction-manager="txManager"/> 
+0

我有這個罐子上我的圖書館org.springframework.transaction-3.1.1.RELEASE.jar。而我不是使用Maven – FERESSS 2013-04-08 10:10:40

+0

這是同樣的ERREUR! ! – FERESSS 2013-04-08 10:10:59

+0

<! - 此處指定了txManager的標識 - > < - 雖然transactionManager在此處引用 - > FERESSS 2013-04-08 10:15:18

0

spring-tx.jar文件應該有你的classpath這意味着它應該出現在您的應用程序的(i.e. WEB-INF/lib)文件夾

檢查您是否只有一個spring-tx.jar具有多個相同類型的罐子也可能導致NoClassDefFoundError

+0

它是一樣的:(我有所有的罐子彈簧3.1和我創建我自己的庫附加到該項目。我檢查有一個名爲org.springframework.transaction-3.1.1.RELEASE.jar的jar事務 – FERESSS 2013-04-08 10:50:49

0

嘗試在你的pom.xml添加此

<dependency> 
    <groupId>aopalliance</groupId> 
    <artifactId>aopalliance</artifactId> 
    <version>1.0</version> 
</dependency> 
+0

這種聯合jar將您的事務管理器綁定到您的Spring應用程序 – Sudipta 2017-09-05 12:54:52