加入收藏 | 设为首页 | 会员中心 | 我要投稿 湖南网 (https://www.hunanwang.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 建站 > 正文

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

发布时间:2019-08-07 23:34:41 所属栏目:建站 来源:黄玲峰
导读: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>

(编辑:湖南网)

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

热点阅读