Java 文件配置Hibernate4和Spring3
我从Spring3Hibernate4开始使用这项新技术,并尝试从教程中执行以下示例。每次我都会犯同样的错误。我使用Spring3.1.1Hibernate4.1.0Java 文件配置Hibernate4和Spring3,java,hibernate,spring-3,hibernate-4.x,Java,Hibernate,Spring 3,Hibernate 4.x,我从Spring3Hibernate4开始使用这项新技术,并尝试从教程中执行以下示例。每次我都会犯同样的错误。我使用Spring3.1.1Hibernate4.1.0 <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<?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>
确保类路径上有相应版本的spring-tx.jar、spring-orm.jar和hibernate-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"/>
spring-tx.jar
文件应该在类路径中,这意味着它应该出现在应用程序的(即WEB-INF/lib)
文件夹中
检查您是否只有一个
spring-tx.jar
具有多个相同类型的jar也会导致NoClassDefFoundError
尝试将其添加到pom.xml中
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>
奥帕林
奥帕林
1
我的库org.springframework.transaction-3.1.1.RELEASE.jar上有这个jar。我没有使用Maven。你的类路径上有spring-orm.jar和hibernate-entitymanager.jar吗?我的新消息错误发生在处理XML“org/aopalliance/intercept/MethodInterceptor”时。查看错误日志了解更多详细信息您需要spring-aop.jar它是一样的:(我有所有的jar spring 3.1,我创建了我自己的附加到项目的库。我检查是否有一个名为org.springframework.transaction-3.1.1.RELEASE.jar的jar事务。这个AOPaliance jar将您的事务管理器绑定到您的spring应用程序
<tx:annotation-driven transaction-manager="txManager"/>
<dependency>
<groupId>aopalliance</groupId>
<artifactId>aopalliance</artifactId>
<version>1.0</version>
</dependency>