加入收藏 | 设为首页 | 会员中心 | 我要投稿 晋中站长网 (https://www.0354zz.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 运营中心 > 建站资源 > 优化 > 正文

一个项目的SpringCloud微服务改造过程

发布时间:2019-08-07 07:48:48 所属栏目:优化 来源:黄玲峰
导读:SSO是公司一个已经存在了若干年的项目,后端采用SpringMVC、MyBatis,数据库使用MySQL,前端展示使用Freemark。今年,我们对该项目进行了一次革命性的改进,将其改造成SpringCloud架构,并且把前后端分离,前端采用Vue框架。 一、使用SpringCloud架构进行

Spring事务有两种处理方式:

  • 编程式

用TransactionTemplate或者直接使用底层的PlatformTransactionManager将事务代码写在业务代码中。
优点:可以在代码块中处理事务,比较灵活。 
缺点:对代码具有侵入性。

  • 声明式

采用@Transactional注解或者基于配置文件方式,在方法前后进行拦截。
优点:非侵入性不会污染代码。
缺点:事务只能在方法和类上控制,粒度较小。
A、使用@Transactional注解
非SpringBoot工程,需要在配置文件中加入配置:

  1. <tx:annotation-driven/>
     

SpringBoot工程可以用@EnableTransactionManagement注解代替上面的配置内容。
B、采用配置文件方式 
之前的sso是基于配置的方式,配置代码如下:

  1. <aop:config> 
  2.       <aop:pointcut expression="execution(public * com.creditease.permission.service.impl.*Impl.*(..))" id="pointcut"/> 
  3.       <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut"/> 
  4.   </aop:config> 
  5.   <tx:advice id="txAdvice" transaction-manager="transactionManager"> 
  6.       <tx:attributes> 
  7.           <tx:method name="query*" propagation="REQUIRED" read-only="true"/> 
  8.           <tx:method name="find*" propagation="REQUIRED" read-only="true"/> 
  9.           <tx:method name="save*" propagation="REQUIRED"/> 
  10.           <tx:method name="delete*" propagation="REQUIRED"/> 
  11.           <tx:method name="add*" propagation="REQUIRED"/> 
  12.           <tx:method name="modify*" propagation="REQUIRED"/> 
  13.       </tx:attributes> 
  14.   </tx:advice>

(编辑:晋中站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读