1. <?xml version="1.0" encoding="UTF-8"?>
  2. <beans xmlns="http://www.springframework.org/schema/beans"
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  4. xmlns:aop="http://www.springframework.org/schema/aop"
  5. xmlns:tx="http://www.springframework.org/schema/tx"
  6. xmlns:context="http://www.springframework.org/schema/context"
  7. xsi:schemaLocation="http://www.springframework.org/schema/beans
  8. http://www.springframework.org/schema/beans/spring-beans.xsd
  9. http://www.springframework.org/schema/tx
  10. http://www.springframework.org/schema/tx/spring-tx.xsd
  11. http://www.springframework.org/schema/aop
  12. >
  13. <bean id="transactionManager"
  14. class="org.springframework.orm.hibernate3.HibernateTransactionManager"
  15. abstract="false" lazy-init="default" autowire="default"
  16. dependency-check="default">
  17. <property name="sessionFactory">
  18. <ref bean="sessionFactory" />
  19. </property>
  20. </bean>
  21. <tx:advice id="txAdvice" transaction-manager="transactionManager">
  22. <tx:attributes>
  23. <tx:method name="add*" propagation="REQUIRED" />
  24. <tx:method name="delete*" propagation="REQUIRED" />
  25. <tx:method name="update*" propagation="REQUIRED" />
  26. <tx:method name="add*" propagation="REQUIRED" />
  27. <!-- <tx:method name="*" propagation="true" />-->
  28. </tx:attributes>
  29. </tx:advice>
  30. <aop:config>
  31. <aop:pointcut id="allManagerMethod"
  32. expression="execution(* com.service.*.*(..))" />
  33. <aop:advisor advice-ref="txAdvice"
  34. pointcut-ref="allManagerMethod" />
  35. </aop:config>
  36. </beans>

Eclipse不能识别<tx:advice/>标签

在开发Spring的过程中,有时会出现Eclipse不能识别<tx:advice/>标签。

提示出现以下错误:

The prefix "tx" for element "tx:advice" is not bound

这个错误的原因很简单是:

我们在定义申明AOP的时候。。没有加载schema。

具体表现如下:

  1. <beans>
  2. <tx:advice
    id="txAdvice"
    transaction-manager="transactionManager">
  3. <tx:attributes>
  4. <tx:method
    name="get*"
    read-only="true"/>
  5. <tx:method
    name="*"
    propagation="REQUIRES_NEW"
    rollback-for="Exception"/>
  6. </tx:attributes>
  7. </tx:advice>
  8. <!-- aop代理设置-->
  9. <aop:config
    proxy-target-class="true">
  10. </aop:config>
  11. </beans>

这时会抛出异常不认<TX>标签。。起先还以为是没有加载JAR包呢。。

后来读AOP文档才发现<beans>中要加入“xmlns:aop”的命名申明,并在“xsi:schemaLocation”中指定aop配置的schema的地址

配置文件如下:

  1. <?xml
    version="1.0"
    encoding="UTF-8"?>
  2. <beans
    xmlns="http://www.springframework.org/schema/beans "
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance "
  4. xmlns:aop="http://www.springframework.org/schema/aop "
  5. xmlns:tx="http://www.springframework.org/schema/tx "
  6. xsi:schemaLocation="http://www.springframework.org/schema/beans
  7. http://www.springframework.org/schema/beans/spring-beans.xsd
  8. http://www.springframework.org/schema/tx
  9. http://www.springframework.org/schema/tx/spring-tx.xsd
  10. http://www.springframework.org/schema/aop
  11. >

这些才是最关键的地方。。后面的配置不变。。。。

Spring使用 <tx:advice>和 <aop:config> 用来配置事务,具体如何配置你可以参考Spring文档。

综上:包com.evan.crm.service下的任意class的具有任意返回值类型、任意数目参数和任意名称的方法

<tx:advice/> 有关的设置

这一节里将描述通过 <tx:advice/> 标签来指定不同的事务性设置。默认的 <tx:advice/> 设置如下:

事务传播设置是 REQUIRED

隔离级别是 DEFAULT

事务是 读/写

事务超时默认是依赖于事务系统的,或者事务超时没有被支持。

任何 RuntimeException 将触发事务回滚,但是任何 checked Exception 将不触发事务回滚

这些默认的设置当然也是可以被改变的。 <tx:advice/> 和 <tx:attributes/> 标签里的 <tx:method/> 各种属性设置总结如下:

表 9.1. <tx:method/> 有关的设置

属性 是否需要? 默认值 描述
name   与事务属性关联的方法名。通配符(*)可以用来指定一批关联到相同的事务属性的方法。 如:'get*'、'handle*'、'on*Event'等等。
propagation REQUIRED 事务传播行为
isolation DEFAULT 事务隔离级别
timeout -1 事务超时的时间(以秒为单位)
read-only false 事务是否只读?
rollback-for   将被触发进行回滚的 Exception(s);以逗号分开。 如:'com.foo.MyBusinessException,ServletException'
no-rollback-for   不 被触发进行回滚的 Exception(s);以逗号分开。 如:'com.foo.MyBusinessException

[转]spring tx:advice 和 aop:config 配置事务的更多相关文章

  1. spring tx:advice 和 aop:config 配置事务

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  2. spring.net tx:advice 和 aop:config 配置事务 匹配名字的方法管理事务

    在网上找到的都是java里的配置方式,后来认真读了下spring.net的帮助文档,解决了这个问题:现在把我的server层的配置文件copy出来: <?xml version="1. ...

  3. spring cloud 2.x版本 Config配置中心教程

    前言 本文采用Spring cloud本文为2.1.8RELEASE,version=Greenwich.SR3 本文基于前面的文章eureka-server的实现. 参考 eureka-server ...

  4. Spring Boot 中使用 @Transactional 注解配置事务管理

    事务管理是应用系统开发中必不可少的一部分.Spring 为事务管理提供了丰富的功能支持.Spring 事务管理分为编程式和声明式的两种方式.编程式事务指的是通过编码方式实现事务:声明式事务基于 AOP ...

  5. Spring Boot中使用@Transactional注解配置事务管理

    事务管理是应用系统开发中必不可少的一部分.Spring 为事务管理提供了丰富的功能支持.Spring 事务管理分为编程式和声明式的两种方式.编程式事务指的是通过编码方式实现事务:声明式事务基于 AOP ...

  6. spring aop方式配置事务中的三个概念 pointcut advice advisor

    AOP的3个关键概念 因为AOP的概念难于理解,所以在前面首先对Java动态代理机制进行了一下讲解,从而使读者能够循序渐进地来理解AOP的思想. 学习AOP,关键在于理解AOP的思想,能够使用AOP. ...

  7. spring tx:advice事务配置

    http://blog.csdn.net/bao19901210/article/details/17226439 http://blog.csdn.net/rong_wz/article/detai ...

  8. Spring配置事务 http://www.cnblogs.com/leiOOlei/p/3725911.html

    http://www.cnblogs.com/leiOOlei/p/3725911.html JNDI方式配置数据源: <?xml version="1.0" encodin ...

  9. Spring声明式事务(xml配置事务方式)

    Spring声明式事务(xml配置事务方式) >>>>>>>>>>>>>>>>>>>& ...

随机推荐

  1. 转 TCP中的序号和确认号

    在网络分析中,读懂TCP序列号和确认号在的变化趋势,可以帮助我们学习TCP协议以及排查通讯故障,如通过查看序列号和确认号可以确定数据传输是否乱 序.但我在查阅了当前很多资料后发现,它们大多只简单介绍了 ...

  2. python基础===open()文件处理使用介绍

    本文转自:Python open()文件处理使用介绍 1. open()语法open(file[, mode[, buffering[, encoding[, errors[, newline[, c ...

  3. 测试mysqldump 压缩率和时间消耗

    测试mysqldump 压缩率和时间消耗 实验总结: 从本次实验数据可以看出,mysqldump通过|gzip参数可以将导出文件压缩53%,同时耗时也普通非压缩模式的2.3倍. 数据库环境: #[ro ...

  4. Python抓取花瓣网高清美图

    一:前言 嘀嘀嘀,上车请刷卡.昨天看到了不错的图片分享网——花瓣,里面的图片质量还不错,所以利用selenium+xpath我把它的妹子的栏目下爬取了下来,以图片栏目名称给文件夹命名分类保存到电脑中. ...

  5. windows server 2012 IIS配置之FTP站点

    原文地址:[原创]winserver2012IIS配置之FTP站点作者:hkmysterious   一.实验拓扑: 使server2012客户计算机通过ftp方式从FTP服务器上下载已上传并共享的文 ...

  6. mac下谷歌chrome浏览器的快捷键

    1. 标签页和窗口快捷键 ⌘-N 打开新窗口. ⌘-T 打开新标签页. ⌘-Shift-N 在隐身模式下打开新窗口. 按 ⌘-O,然后选择文件. 在 Chrome 浏览器中打开计算机中的文件. 按住  ...

  7. 接口测试Session/Cookie笔记(二)

    Windows系统运行计算器命令:calc python显示上一步操作命令:Alt+p python显示上一步操作结果:_(英文下划线) Session是存放在服务器的键值对 ,用于保存客户端的某个特 ...

  8. C#取出字符串中的数字或字母

    string str20 = "ABC123"; string strSplit1,strSplit2; //取出字符串中所有的英文字母 strSplit1 = Regex.Rep ...

  9. 176. Second Highest Salary

    Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...

  10. 关于k8s里的service互访,有说法

    昨天,测试了一个项目的接入.明白了以下几个坑: 1,traefik有可能有性能问题,如果daemonset安装,可重建.也需要通过8580端口查看性能. 2,集群中的service访问自己时,好像性能 ...