java - 处理 XML 时发生错误“无法加载类 [org.springframework.transaction.annotation.AnnotationTransactionAttributeSource]

标签 java xml spring hibernate applicationcontext

请我需要配置文件applicationcontext.xml,我使用hibernate 5.2.10和spring 3.1.1。
我已经有了这个配置,但有一个错误:

"Error occured processing XML 'Unable to load class [org.springframework.transaction.annotation.AnnotationTransactionAttributeSource]. Are you running on Java 1.5+? Root cause: java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.forName(Ljava/lang/String;)Ljava/lang/Class;'. See Error Log for more details"

<?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">

        <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
            <property name="url" value="jdbc:mysql://localhost/training"></property>
            <property name="username" value="root"></property>
            <property name="password" value=""></property>
        </bean>

        <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
            <property name="dataSource" ref="dataSource"></property>
            <property name="annotatedClasses">
                <list>
                    <value>co.ma.training.entity.Stagiaire</value>
                </list>
            </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                </props>
            </property>
        </bean>

        <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
            <property name="sessionFactory" ref="sessionFactory"></property>
        </bean>
        <tx:annotation-driven transaction-manager="transactionManager" />

        <context:annotation-config></context:annotation-config>
        <context:component-scan base-package="co.ma.training"></context:component-scan>

</beans>

最佳答案

请确保在您的项目中使用与框架兼容的最新 Java 版本。 (1.5+)

如果您使用 Maven,请尝试使用以下属性。

<properties>
    <maven.compiler.source>1.8</maven.compiler.source>
    <maven.compiler.target>1.8</maven.compiler.target>
</properties>

关于java - 处理 XML 时发生错误“无法加载类 [org.springframework.transaction.annotation.AnnotationTransactionAttributeSource],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45401185/

相关文章:

java - 将 Java 对象转换为 XML 时的 XStream 撇号问题

android - 以编程方式设置主题。如何重新加载要申请的 Activity

java - 使用条件 AND NOT EXISTS 将 SQL 转换为 HQL

java - 在异步任务中使用 Spring Data Session bean。范围 'session' 对于当前线程不活动

java - 如何使用 Java 或 pellet 将 SWRL 规则添加到本体中?

java - 了解给定代码的代码执行路径

java - 使用 PowerMockito 模拟 Java 中其他类的静态函数

php - simplexml 帮助我如何解析这个?

带有键,值类型消息的spring cloud stream SOURCE

java - 使用 @PathVariable 重定向到另一个 Controller