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. Django2.0如何配置urls文件

    刚开始学django,创建的第一个工程无法启动,后来发现是由于教程是针对较低版本的Django,我用的是Django2.0和Python3.6,两个都是发文为止的最新版本,urls文件设置方法和旧版本 ...

  2. c#导出文件,下载文件,命名下载后的文件名

    Page.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpU ...

  3. EOS.IO技术学习

    如今很火的项目EOS的学习,以下主要的内容是基于白皮书 参考: http://chainx.org/paper/index/index/id/20.html EOS.IO软件引入了一种新的块链架构,旨 ...

  4. JavaScript知识点的总结

    一.Javascript的含义 是一种解释性的语言,主要给网页添加各色各样的动态功能,同时为用户提供浏览效果. 二.JavaScript的主要特点 1. 简单性 2. 动态性 3. 安全性 4. 跨平 ...

  5. 深入浅出Node.js(一) - 初识Node.js

    1.Node.js将Javascript解决不确定性所使用的事件驱动方式引入了进来,因为JS是一门事件驱动的语言,旨在能够对外界的事件作出响应; 2.Node.js中,所有的有关异步的操作,都在同步操 ...

  6. WEB前端之HTML5~HTML5与HTML4的区别

    推出的理由及目标 WEB浏览器存在的问题包括以下三点 世界知名浏览器厂商对HTML5的支持 语法的改变 DOCTYPE的声明 XHTML的DOCTYPE声明方式 HTML4的DOCTYPE声明方式 H ...

  7. JQUERY 提取多个元素 a img 的 src href

    <div class="abc"><a href="1.html"><img src="1.jpg"/> ...

  8. form 表单获取所有数据 封装方法

    function getFormJson(frm) { var o = {}; var a = $(frm).serializeArray(); $.each(a, function () { if ...

  9. 《深入浅出MyBatis技术原理与实战》——6. MyBatis的解析和运行原理

    MyBatis的运行分为两大部分,第一部分是读取配置文件缓存到Configuration对象,用以创建SqlSessionFactory,第二部分是SqlSession的执行过程. 6.1 涉及的技术 ...

  10. 微信小程序实战篇-图片的预览、二维码的识别

    开篇 今天,做的小程序项目要求,个人中心的客服图片在用户长按时可以识别其二维码,各种翻阅查找,采坑很多,浪费了很多时间,在这里记录下需要注意的点,以及对小程序官方提供的API做一个正确和清晰的认知,希 ...