【问题标题】:Error occured processing XML 'Unable to load class [org.springframework.transaction.annotation.AnnotationTransactionAttributeSource]处理 XML 时发生错误“无法加载类 [org.springframework.transaction.annotation.AnnotationTransactionAttributeSource]
【发布时间】:2018-01-06 03:47:31
【问题描述】:

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

“处理 XML 时发生错误'无法加载类 [org.springframework.transaction.annotation.AnnotationTransactionAttributeSource]。 你在 Java 1.5+ 上运行吗?根本原因: java.lang.NoSuchMethodError: org.springframework.util.ClassUtils.forName(Ljava/lang/String;)Ljava/lang/Class;'。 有关详细信息,请参阅错误日志”

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

【问题讨论】:

  • 您正在混合来自不同版本的 Spring 的 jar。不要混合使用弹簧版本。

标签: java xml spring hibernate applicationcontext


【解决方案1】:

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

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

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

【讨论】:

  • 我使用 Java 版本 8 (Jdk8)。
  • 我用一个项目web动态
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-02-11
  • 2014-07-29
  • 2014-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多