您当前的位置: 首页 >  spring

qq_34412985

暂无认证

  • 1浏览

    0关注

    1061博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

spring中使用事务的2种方式:编程式事务和声明式事务

qq_34412985 发布时间:2020-04-13 13:29:55 ,浏览量:1

编程式事务

TransactionTemplate 其中设置当前操作传播特性,隔离,超时propagtion isolation timeout

     •TransactionCallback

     •TransactionCallbackWithoutResult

PlatformTransactionManager

     •可以传⼊入TransactionDefinition进⾏行行定义

声明式事务     

利用aop的proxy,在目标方法上做了层封装,帮助用户进行模板式事务操作,在操作开始前启动事务,在方法执行结束后commit或rollback这个事务。使用java默认的基于接口的动态代理,封装了aspectJ,有切入点Advice,返回值的AfterReturning,在方法执行前有before,在方法后After,抛出异常时AfterThrowing,在这里使用的是Around切入也就是在方法前后去做了一段的增强。

基于注解的配置⽅方式        instertruction?

开启事务注解的⽅方式                                                           @Transactional

•@EnableTransactionManagement                                        •transactionManager  dataSourceTransactionManager 

•                                                          •propagation

一些配置                                                                                   •isolation

•proxyTargetClass  定义基于接口还是类  true orfalse              •timeout

•mode   aop model是否使用aspectJ默认使用java就好             •readOnly

•order 事务拦截顺序默认最低                                                   •怎么判断回滚 设置遇到特定异常类时回滚

关注
打赏
1653291990
查看更多评论
立即登录/注册

微信扫码登录

0.0386s