Java自学者论坛

 找回密码
 立即注册

手机号码,快捷登录

恭喜Java自学者论坛(https://www.javazxz.com)已经为数万Java学习者服务超过8年了!积累会员资料超过10000G+
成为本站VIP会员,下载本站10000G+会员资源,会员资料板块,购买链接:点击进入购买VIP会员

JAVA高级面试进阶训练营视频教程

Java架构师系统进阶VIP课程

分布式高可用全栈开发微服务教程Go语言视频零基础入门到精通Java架构师3期(课件+源码)
Java开发全终端实战租房项目视频教程SpringBoot2.X入门到高级使用教程大数据培训第六期全套视频教程深度学习(CNN RNN GAN)算法原理Java亿级流量电商系统视频教程
互联网架构师视频教程年薪50万Spark2.0从入门到精通年薪50万!人工智能学习路线教程年薪50万大数据入门到精通学习路线年薪50万机器学习入门到精通教程
仿小米商城类app和小程序视频教程深度学习数据分析基础到实战最新黑马javaEE2.1就业课程从 0到JVM实战高手教程MySQL入门到精通教程
查看: 325|回复: 0

解决在Spring整合Hibernate配置tx事务管理器出现错误的问题

[复制链接]
  • TA的每日心情
    奋斗
    前天 11:25
  • 签到天数: 792 天

    [LV.10]以坛为家III

    2049

    主题

    2107

    帖子

    72万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    723136
    发表于 2021-6-29 15:34:18 | 显示全部楼层 |阅读模式

    问题描述:

    Error occured processing XML 'org/aopalliance/intercept/MethodInterceptor'. See Error Log for more details

    全部配置如下: 

     1 <?xml version="1.0" encoding="UTF-8"?>
     2 <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
     3         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
     4         http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
     5         http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd">
     6     
     7     <!-- 配置自动扫描的包 -->
     8     <context:component-scan base-package="com.mcs.hibernate"></context:component-scan>
     9 
    10     <!-- 配置数据源 -->
    11     <!-- 导入资源文件 -->
    12     <context:property-placeholder location="classpath:db.properties"/>        
    13     <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource">
    14         <property name="user" value="${jdbc.user}"></property>
    15         <property name="password" value="${jdbc.password}"></property>
    16         <property name="driverClass" value="${jdbc.driverClass}"></property>
    17         <property name="jdbcUrl" value="${jdbc.jdbcUrl}"></property>
    18         
    19         <property name="initialPoolSize" value="${c3p0.initialPoolSize}"></property>
    20         <property name="maxPoolSize" value="${c3p0.maxPoolSize}"></property>
    21     </bean>
    22     
    23     <!-- 配置Hibernate SessionFactory -->
    24     <bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
    25         <property name="dataSource" ref="dataSource"></property>
    26         
    27         <!-- 加载Hibernate的配置文件 -->
    28         <property name="configLocation" value="classpath:hibernate.cfg.xml"></property>
    29         <!-- 加载Hibernate 映射文件的位置及名称, 可以使用通配符 -->        
    30         <property name="mappingLocations" value="classpath:com/mcs/hibernate/entities/*.hbm.xml"></property>
    31     </bean>
    32     
    33     <!-- 配置 Spring 的声明式事务 -->
    34     <!-- 1. 配置事务管理器 -->
    35     <bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    36         <property name="sessionFactory" ref="sessionFactory"></property>
    37     </bean>
    38 
    39     <!-- 2. 配置事务属性, 需要事务管理器 -->
    40     <tx:advice id="txAdvice" transaction-manager="transactionManager">
    41         <tx:attributes>
    42             <tx:method name="get*" read-only="true"/>
    43             <tx:method name="*"/>
    44         </tx:attributes>
    45     </tx:advice>
    46 
    47     <!-- 3. 配置事务切点, 并把切点和事务属性关联起来 -->
    48     <aop:config>
    49         <aop:pointcut expression="execution(* com.mcs.hibernate.service.*.*(..))" 
    50             id="txPointcut"/>
    51         <aop:advisor advice-ref="txAdvice" pointcut-ref="txPointcut"/>
    52     </aop:config>
    53 
    54 </beans>
    View Code

    解决方法:加入以下两个Jar包即可

    哎...今天够累的,签到来了1...
    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    QQ|手机版|小黑屋|Java自学者论坛 ( 声明:本站文章及资料整理自互联网,用于Java自学者交流学习使用,对资料版权不负任何法律责任,若有侵权请及时联系客服屏蔽删除 )

    GMT+8, 2024-9-16 04:32 , Processed in 0.061625 second(s), 29 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2021, Tencent Cloud.

    快速回复 返回顶部 返回列表