我最近通过SPRING + Hibernate项目升级到Spring 4.1.6并将Hibernate升级到Hibernate 4.3.5。但是这样做我得到了这个异常
Error creating bean with name 'transactionManager' defined in class path resource [fileName]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/QueryTimeoutException
这是具有Hibernated依赖关系的POM文件,我使用PostgreSQL作为数据库
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.3.5.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.0.2.Final</version>
</dependency>
<dependency>
<groupId>postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.1-901.jdbc4</version>
</dependency>
这是fileName
中的配置<bean id = "transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" lazy-init="true">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="get*" read-only="true" propagation="REQUIRED"/>
<tx:method name="*" propagation="REQUIRED"/>
</tx:attributes>
</tx:advice>
解决这个问题的任何帮助都会非常明显。
答案 0 :(得分:3)
从错误中
Error creating bean with name 'transactionManager' defined in class path resource [fileName]: Invocation of init method failed; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/QueryTimeoutException
很明显,容器无法加载类文件QueryTimeoutException
。
该文件附带spring-tx-4.1.6.RELEASE.jar
添加此依赖项
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>4.1.6.RELEASE</version>
</dependency>