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. HTTP响应码摘自apach官网

    HTTP状态列表 响应码由三位十进制数字组成,它们出现在由HTTP服务器发送的响应的第一行. 响应码分五种类型,由它们的第一位数字表示: 1xx:信息,请求收到,继续处理 2xx:成功,行为被成功地接 ...

  2. SQL注入之逗号拦截绕过

    目前所知博主仅知的两个方法 1.通过case when then 2.join [一]case when then mysql,,,,,,, ) ) end; +----+-----------+-- ...

  3. Python基础===使用virtualenv创建一个新的运行环境

    virtualenv简直是一个神器,以ubuntu环境为例, 先安装virtualenv 然后执行如下命令: 多版本创建env的方式: virtualenv 虚拟环境文件目录名 python=pyth ...

  4. 在linux内核中获得比jiffies精度更高的时间值【转】

    转自:http://blog.chinaunix.net/uid-20672257-id-2831219.html 内核一般通过jiffies值来获取当前时间.尽管该数值表示的是自上次系统启动到当前的 ...

  5. 在Caffe中使用 DIGITS(Deep Learning GPU Training System)自定义Python层

    注意:包含Python层的网络只支持单个GPU训练!!!!! Caffe 使得我们有了使用Python自定义层的能力,而不是通常的C++/CUDA.这是一个非常有用的特性,但它的文档记录不足,难以正确 ...

  6. HTML5API

    H5新API 一.地理位置API 1.navigator.geolocation对象 getCurrentPosition(callback,errCallback,options)获取当前位置 wa ...

  7. 浅谈Javascript设计模式

    什么是模式 模式是一种可复用的解决方案,可用于解决软件设计中遇到的常见问题. 也就是说用来解决常见问题的可复用的解决方案. 常见的js设计模式 Constructor(构造器)模式 Construct ...

  8. 阿里云Centos等更新源设置成阿里源方法。

    https://help.aliyun.com/knowledge_detail/5974184.html ---------------------------------------------- ...

  9. ZK客户端

    说明:本文为读<从Paxos到Zookeeper 分布式一致性原理与实践>读书笔记 shell操作 Java客户端 原始API pom文件: <dependency> < ...

  10. HDU 5514.Frogs-欧拉函数 or 容斥原理

    Frogs Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submi ...