事务管理: 管理事务,管理数据,数据完整性和一致性

事务[业务逻辑] : 由一系列的动作[查询书价格,更新库存,更新余额],组成一个单元[买书业务],

当我们动作当中有一个错了,全错~

ACID

原子性 隔离性 一致性 持久性

注解方式配置事务[编程方式-->@代码]

1.Spring框架当中需要配置事务管理器--> JDBC[Mybatis] Hibernate JTA-->数据源

2.启动事务注解[特意说了,事务管理器的id]

3.事务注解--> 可以放置的位置:@Transaction 类或者方法上

  1. 类上放置注解 方法当中注解[reaonly=true]
  2. rollbakFor
  3. 传播性 7个 默认值

XML方式配置事务

<!--

声明方式XML方式:完成事务的配置,需要使用到地方有AOP

-->

<!-- 配置事务管理器 -->

<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">

<property name="dataSource" ref="dataSource"/>

</bean>

<!-- 定义哪些方法需要被事务管理器进行管理 -->

<tx:advice id="serviceMethodAdvice" transaction-manager="transactionManager">

<tx:attributes>

<tx:method name="*" read-only="true"/>

</tx:attributes>

</tx:advice>

<!-- 需要哪些方法是被监控,并且是有事务管理 -->

<aop:config>

<aop:pointcut expression="execution(* com..service.*Service.*(..))" id="servicePointCut"/>

<!-- 代表的意思: service包下的说有类以Service结尾的类下的所有方法,都为只读状态 -->

<aop:advisor advice-ref="serviceMethodAdvice" pointcut-ref="servicePointCut"/>

</aop:config>

单元测试,推荐使用断言方式,需要再使用syso的输出方式

<!-- 定义哪些方法需要被事务管理器进行管理 -->

<tx:advice id="serviceMethodAdvice" transaction-manager="transactionManager">

<tx:attributes>

<!-- 约定大于配置 -->

<!-- 第一种配置方式

<tx:method name="*" read-only="true"/>

<tx:method name="add*" propagation="REQUIRED"/>

<tx:method name="insert*"/>

<tx:method name="create*"/>

<tx:method name="update*"/>

<tx:method name="edit*"/>

<tx:method name="mod*"/>

<tx:method name="change*"/>

<tx:method name="del*"/>

<tx:method name="remove*"/>

<tx:method name="cancel*"/>

-->

<!-- 第二种配置方式 -->

<tx:method name="*" read-only="false" />

<tx:method name="get*" read-only="true"/>

<tx:method name="load*" read-only="true"/>

<tx:method name="list*" read-only="true"/>

<tx:method name="find*" read-only="true"/>

<tx:method name="sel*" read-only="true"/>

<tx:method name="query*" read-only="true"/>

</tx:attributes>

</tx:advice>

在这里胖哥想说的,帮助文档一定要看,有一些事情我强调了很多很多遍,你们不走心,我也无能为力!

Again in keeping with Spring's philosophy, the TransactionException that can be thrown by any of the PlatformTransactionManager interface's methods is unchecked (that is, it extends the java.lang.RuntimeException class). Transaction infrastructure failures are almost invariably fatal. In rare cases where application code can actually recover from a transaction failure, the application developer can still choose to catch and handle TransactionException. The salient point is that developers are not forced to do so.

The getTransaction(..) method returns a TransactionStatus object, depending on a TransactionDefinition parameter. The returned TransactionStatus might represent a new transaction, or can represent an existing transaction if a matching transaction exists in the current call stack. The implication in this latter case is that, as with Java EE transaction contexts, a TransactionStatus is associated with a thread of execution.

The TransactionDefinition interface specifies:

  • Isolation: The degree to which this transaction is isolated from the work of other transactions. For example, can this transaction see uncommitted writes from other transactions?
  • Propagation: Typically, all code executed within a transaction scope will run in that transaction. However, you have the option of specifying the behavior in the event that a transactional method is executed when a transaction context already exists. For example, code can continue running in the existing transaction (the common case); or the existing transaction can be suspended and a new transaction created. Spring offers all of the transaction propagation options familiar from EJB CMT. To read about the semantics of transaction propagation in Spring, see Section 16.5.7, "Transaction propagation".
  • Timeout: How long this transaction runs before timing out and being rolled back automatically by the underlying transaction infrastructure.
  • Read-only status: A read-only transaction can be used when your code reads but does not modify data. Read-only transactions can be a useful optimization in some cases, such as when you are using Hibernate.

重点: 绝对是个人的建议

RuntimeException默认是不受审查,也是rollBackFor的默认值,如果你再Service层或者Dao层对其进行捕获的话,那么一定要做处理

个人的建议为: service和Dao不管遇到什么请求你都处理往外抛, 处理都放置在Controller 关于异常尽量都是用继承RuntimeException,根据你的代码情况进行不同异常的封装

今天的笔记做的不好! 累了!~~~ 付出的越多!~~~ 有的时候失望越多!~~~ 该何去何从!~~~~

第六节 事务XML方式[声明方式]的更多相关文章

  1. Spring中事务的XML方式[声明方式]

    事务管理: 管理事务,管理数据,数据完整性和一致性 事务[业务逻辑] : 由一系列的动作[查询书价格,更新库存,更新余额],组成一个单元[买书业务], 当我们动作当中有一个错了,全错~ ACID 原子 ...

  2. ES6第二节:新的声明方式

    通过上一节的环境搭建完成,接下来我们就可以愉快的探索ES6的新世界了!下面我们从新的声明方式开始: 在ES6里新加了两种声明方式:let 和 const,以前我们都是用var去作声明,接下来我们一一比 ...

  3. 【系统学习ES6】第一节:新的声明方式

    [系统学习ES6] 本专题旨在对ES6的常用技术点进行系统性梳理,帮助大家对其有更好的掌握.计划每周更新1-2篇,希望大家有所收获. 以前用ES5时,声明变量只能用var.ES6的出现,为我们带来了两 ...

  4. 第六节:WebApi的部署方式(自托管)

    一. 简单说明 开篇就介绍过WebApi和MVC相比,其中优势之一就是WebApi可以不依赖于IIS部署,可以自托管,当然这里指的是 .Net FrameWork 下的 WebApi 和 MVC 相比 ...

  5. ASP.NET MVC深入浅出系列(持续更新) ORM系列之Entity FrameWork详解(持续更新) 第十六节:语法总结(3)(C#6.0和C#7.0新语法) 第三节:深度剖析各类数据结构(Array、List、Queue、Stack)及线程安全问题和yeild关键字 各种通讯连接方式 设计模式篇 第十二节: 总结Quartz.Net几种部署模式(IIS、Exe、服务部署【借

    ASP.NET MVC深入浅出系列(持续更新)   一. ASP.NET体系 从事.Net开发以来,最先接触的Web开发框架是Asp.Net WebForm,该框架高度封装,为了隐藏Http的无状态模 ...

  6. android解析xml文件的方式

    android解析xml文件的方式   作者:东子哥 ,发布于2012-11-26,来源:博客园   在androd手机中处理xml数据时很常见的事情,通常在不同平台传输数据的时候,我们就可能使用xm ...

  7. 第一百二十六节,JavaScript,XPath操作xml节点

    第一百二十六节,JavaScript,XPath操作xml节点 学习要点: 1.IE中的XPath 2.W3C中的XPath 3.XPath跨浏览器兼容 XPath是一种节点查找手段,对比之前使用标准 ...

  8. spring,springmvc,mybatis基本整合(一)--xml文件配置方式(1)

    **这个整合.仅仅是最主要的整合,而且是xml配置文件的方式之中的一个,即当中的mybatis是採用非mapper接口的方式.(第二遍採用mapper接口方式.第三遍採用注解的方式:第四篇採用注解基于 ...

  9. MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息

    MVVM模式解析和在WPF中的实现(六) 用依赖注入的方式配置ViewModel并注册消息 系列目录: MVVM模式解析和在WPF中的实现(一)MVVM模式简介 MVVM模式解析和在WPF中的实现(二 ...

随机推荐

  1. Error:Could not find common.jar (android.arch.core:common:1.0.0)

    Error:Could not find common.jar (android.arch.core:common:1.0.0). Searched in the following location ...

  2. kubernetes部署mysql

    第一章 部署K8S集群 https://www.cnblogs.com/zoulixiang/p/9504324.html 第二章 1.新建mysql-rc.yaml vi mysql-rc.yaml ...

  3. web前端开发分享-css,js入门篇

    学习没有捷径,但学习是有技巧与方法.   一,css入门篇:   推荐书籍:css哪些事儿,精通css. 理由:css那些事儿,他是一本介绍css基础类的书,是入门的经典读物. 系统的介绍了css的选 ...

  4. FUNMVP:几张图看懂区块链技术到底是什么?(转载)

    几张图看懂区块链技术到底是什么? 本文转载自:http://www.cnblogs.com/behindman/p/8873191.html “区块链”的概念可以说是异常火爆,好像互联网金融峰会上没人 ...

  5. Apache服务器出现Forbidden 403错误提示的解决方法总结

    在配置Linux的 Apache服务时,经常会遇到http403错误,我今天配置测试时也出现了,最后解决了,总结了一下.http 403错误是拒绝访问的意思,有很多原因的.还有,这些问题在win平台的 ...

  6. MongoDB作为Windows服务来安装 错误1053:服务没有及时响应启动或控制请求

    这个问题我解决了一晚上,用尽了所有百度 博客上的方法,都是失败的 结果重新换了一种安装的方法 视频讲解  非常清楚 https://www.bilibili.com/video/av31240330? ...

  7. Final发布 视频展示

    1.视频链接 视频地址:http://v.youku.com/v_show/id_XMzk1OTYyNjE0NA==.html?spm=a2hzp.8244740.0.0 杨老师粉丝群——弹球学成语项 ...

  8. 20135202闫佳歆--week3 跟踪分析Linux内核的启动过程--实验及总结

    实验三:跟踪分析Linux内核的启动过程 一.调试步骤如下: 使用gdb跟踪调试内核 qemu -kernel linux-3.18.6/arch/x86/boot/bzImage -initrd r ...

  9. rethinking virtual network embedding..substrate support for path splitting and migration阅读笔记

    1.引言 网络虚拟化, 1.支持同一个底层网络有多种网络架构,每种架构定制一个应用或用户社区. 2.也可以让多个服务提供者在共同的物理基础设施上定制端到端的服务.如Voice over IP(VoIP ...

  10. 80C51存储器与C51内存优化

    80C51在物理结构上有四个存储空间:片内程序存储器.片外程序存储器.片内数据存储器和片外数据存储器.但在逻辑上,即从用户使用的角度上,80C51有三个存储空间:片内外统一编址的64KB的程序存储器地 ...