Java.lang.NoClassDefFoundError错误: org/springframework/transaction/interceptor/TransactionInterceptor。

3

我正在尝试将Spring 3.1.1与Hibernate 4.0集成。这是我的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
我检查了我的类路径,并有TransactionInterceptor.class。我做错了什么?我需要添加什么吗? 编辑 这是我的lib文件夹:

你的 CLASSPATH 上也有 spring-aop*.jarspring-beans*.jar 吗? - Tomasz Nurkiewicz
正如我在答案中强调的那样 - 你必须检查你的运行时类路径。你展示给我们的是你的编译时类路径。 - Bozho
我通过下载不同的JAR包解决了这个问题。 - user1137146
2
你好,能否详细说明一下你的解决方案?我遇到了同样的问题。谢谢。 - snowfox
1个回答

1
你需要检查你的运行时类路径(即WEB-INF/lib)中的spring-tx-...jar文件(并确保你只有一个这样的文件,而不是多个不同版本的文件)。

我之前检查过,那不是它。 - user1137146
异常表示您要么有多个包含拦截器的JAR文件,这会混淆类加载器。 - Bozho

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接