问题描述
我正在尝试将Spring 3.1.1与Hibernate 4.0集成在一起.这是我的dispatcher-servlet.xml:
I am trying to integrate spring 3.1.1 with hibernate 4.0. This is my dispatcher-servlet.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:lang="http://www.springframework.org/schema/lang"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/lang http://www.springframework.org/schema/lang/spring-lang.xsd
http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.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.xsd">
<context:component-scan base-package="com.future.controllers" />
<context:annotation-config />
<context:component-scan base-package="com.future.services.menu" />
<context:component-scan base-package="com.future.dao" />
<bean id="dataSource"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"
p:driverClassName="com.mysql.jdbc.Driver"
p:url="jdbc:mysql://localhost:3306/bar_visitor2" p:username="root"
p:password=""/>
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/" />
<property name="suffix" value=".jsp" />
</bean>
<bean id="sessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="configLocation">
<value>classpath:hibernate.cfg.xml</value>
</property>
</bean>
<tx:annotation-driven />
<bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>
当我尝试使用@Transactional
注释时,出现错误java.lang.NoClassDefFoundError: org/springframework/transaction/interceptor/TransactionInterceptor
.
When I try to use @Transactional
annotation I am getting an error java.lang.NoClassDefFoundError: org/springframework/transaction/interceptor/TransactionInterceptor
.
我检查了我的类路径,并且有TransactionInterceptor.class
.我究竟做错了什么?我应该添加些东西吗?
I checked my classpath and there is TransactionInterceptor.class
. What am I doing wrong? Should I add something?
修改这是我的lib文件夹:
EditThis is my lib folder:
推荐答案
您需要检查运行时类路径(即WEB-INF/lib)中的spring-tx-...jar
(并确保只有一个这样的罐子,有很多不同版本的罐子
You need to check your runtime classpath (i.e. WEB-INF/lib) for spring-tx-...jar
(and make sure you have only one such jar, not many with different versions)
这篇关于java.lang.NoClassDefFoundError:org/springframework/transaction/interceptor/TransactionInterceptor的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!