zoukankan      html  css  js  c++  java
  • [转]spring tx:advice 和 aop:config 配置事务

     
    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. <bean id="transactionManager" 
    13. class="org.springframework.orm.hibernate3.HibernateTransactionManager" 
    14. abstract="false" lazy-init="default" autowire="default" 
    15. dependency-check="default"
    16. <property name="sessionFactory"
    17. <ref bean="sessionFactory" /> 
    18. </property
    19. </bean
    20. <tx:advice id="txAdvice" transaction-manager="transactionManager"
    21. <tx:attributes
    22. <tx:method name="add*" propagation="REQUIRED" /> 
    23. <tx:method name="delete*" propagation="REQUIRED" /> 
    24. <tx:method name="update*" propagation="REQUIRED" /> 
    25. <tx:method name="add*" propagation="REQUIRED" /> 
    26. <!-- <tx:method name="*" propagation="true" />--> 
    27. </tx:attributes
    28.     </tx:advice
    29.     <aop:config
    30. <aop:pointcut id="allManagerMethod" 
    31. expression="execution(* com.service.*.*(..))" /> 
    32. <aop:advisor advice-ref="txAdvice" 
    33. pointcut-ref="allManagerMethod" /> 
    34. </aop:config
    35. </beans

    Xml代码  收藏代码
    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.  
    11. </aop:config
    12. </beans

    Xml代码  收藏代码
    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 

    属性 是否需要? 默认值 描述
    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
  • 相关阅读:
    部署应用映射外部目录、迁移与备份、容器保存镜像、镜像打压成压缩包、压缩包恢复为镜像、dockerfiles、私有仓库、docker-compose、部署多应用、容器间通信
    docker的介绍、架构图、乌班图、安装、远程仓库、镜像操作、容器操作、应用部署、
    flask-script(制定命令)、sqlschemy、orm的使用、线程安全、增删查改、多表操作、flask-sqlalchemy
    g对象、flask-session、数据库连接池、wtforms(forms组件)、信号
    中间件、猴子补丁、蓝图、请求上下文执行流程
    flask配置文件、模板、request对象的属性和方法、响应对象方法、闪现、session的使用、请求扩展、全局标签、全局过滤器、
    flask入门、配置文件、路由系统、路由的本质、CBV
    基本权限chmod、软件管理-二进制安装、源码安装、进程管理、系统服务、
    对爬取京东商品按照标题为其进行自动分类---基于逻辑回归的文本分类
    学习进度3.16
  • 原文地址:https://www.cnblogs.com/ZhuRenWang/p/4792051.html
Copyright © 2011-2022 走看看