Java学习者论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

手机号码,快捷登录

恭喜Java学习者论坛(https://www.javaxxz.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入门到精通教程
查看: 1266|回复: 0

使用spring管理事务的时候,配置文件的注意事项

  [复制链接]

该用户从未签到

发表于 2011-10-13 13:44:27 | 显示全部楼层 |阅读模式
下面是一个使用spring管理事务的配置文件例子。注意红色部分

<?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:tx="http://www.springframework.org/schema/tx"   
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd   
           http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd   
           http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd"   
        default-autowire="byName" default-lazy-init="true">   
   
   
   
   
   
        <!-- Configure the Spring framework to use JTA transactions from Atomikos -->   
        <bean id="transactionManager1 "   
                class="org.springframework.transaction.jta.JtaTransactionManager">   
        </bean>   
   
   
        <aop:aspectj-autoproxy proxy-target-class="true" />   
   
   
        <aop:config proxy-target-class="true">   
                <aop:advisor   
                        pointcut="execution(* xxx.services.impls.* .*(..))"   
                        advice-ref="txAdvice" />   
        </aop:config>   
   
        <tx:advice id="txAdvice" transaction-manager="transactionManager1 ">   
                <tx:attributes>   
                        <tx:method name="get*" read-only="true"/>   
                        <tx:method name="*" rollback-for="Exception"/>   
                </tx:attributes>   
        </tx:advice>   
   
</beans>   
   
default-autowire="byName"  如果有这个,那么   
   
<bean id="transactionManager1"   
                class="org.springframework.transaction.jta.JtaTransactionManager">   
</bean>   
      这个bean的id,一定不能是transactionManager 否则会出错,原因是  org.springframework.transaction.jta.JtaTransactionManager 这个类有属性也叫 transactionManager ,所以会造成错误。
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-20 02:44 , Processed in 0.344815 second(s), 33 queries .

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

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