当前位置: 首页 > news >正文

什么建设网站江西省水利水电建设集团招标网站

什么建设网站,江西省水利水电建设集团招标网站,关键词优化seo,页面设计有哪几种风格一、前言 微服务架构下#xff0c;多个微服务都需要事务操作#xff0c;如果在每个微服务下都从头配置事务#xff0c;将非常繁锁。事务配置具有高度的一致性#xff0c;可以抽取出来#xff0c;制作starter#xff0c;在需要配置事务的服务中引入starter依赖即可。 采用…一、前言 微服务架构下多个微服务都需要事务操作如果在每个微服务下都从头配置事务将非常繁锁。事务配置具有高度的一致性可以抽取出来制作starter在需要配置事务的服务中引入starter依赖即可。 采用springAOP的方式实现事务 制作过程可以参考 自定义启动器 Starter【保姆级教程】用starter实现Oauth2中资源服务的统一配置 二、制作starter 1、完整结构图 2、引用模块 名称tuwer-transaction-spring-boot-starter 引用模块用于外部引用。只有pom.xml文件 pom.xml ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersiongroupIdcom.tuwer/groupIdartifactIdtuwer-transaction-spring-boot-starter/artifactIdversion1.0-SNAPSHOT/versiondescription事务starter/descriptionpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target!-- 编译编码 --project.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependencies!-- 自动配置模块 --dependencygroupIdcom.tuwer/groupIdartifactIdtuwer-transaction-spring-boot-starter-autoconfigure/artifactIdversion1.0-SNAPSHOT/version/dependency/dependencies /project3、自动配置模块 名称tuwer-transaction-spring-boot-starter-autoconfigure\ 1 pom.xml 使用jdbc的事务管理器 ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsdparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.6.7/version/parentmodelVersion4.0.0/modelVersiongroupIdcom.tuwer/groupIdartifactIdtuwer-transaction-spring-boot-starter-autoconfigure/artifactIdversion1.0-SNAPSHOT/versiondescription事务starter自动配置模块/descriptionpropertiesmaven.compiler.source8/maven.compiler.sourcemaven.compiler.target8/maven.compiler.target!-- 编译编码 --project.build.sourceEncodingUTF-8/project.build.sourceEncoding/propertiesdependencies!-- 基础启动器 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter/artifactId/dependency!-- aop --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-aop/artifactId/dependency!-- 数据库 --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-jdbc/artifactId/dependency/dependencies /project2 切入点属性类 用于外部配置切入点 可以配置多个 如果没有配置就使用默认的execution(* com.tuwer.service..*Impl.*(..))【com.tuwer.service】包及子包下所有以【Impl】结尾的类的所有方法 package com.tuwer.config;import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.util.CollectionUtils;import java.util.HashSet; import java.util.Set;/*** p事务属性类/p** author 土味儿* Date 2023/4/17* version 1.0*/ ConfigurationProperties(prefix tuwer-transaction) public class TransactionProperty {/*** 切入点可以有多个* 格式必须符合要求*/private SetString pointcut new HashSet();/*** 获取切入点表达式可以有多个组合* -----------------------------------* execution(...) || execution(...)* -----------------------------------* return*/public String getPointcutExpression() {// 如果set集合为null或没有值时使用默认值if(CollectionUtils.isEmpty(this.pointcut)){// 默认切入点【com.tuwer.service】包及子包下所有以【Impl】结尾的类的所有方法return execution(* com.tuwer.service..*Impl.*(..));}StringBuilder sb new StringBuilder();// 组合多个切入点for (String p : this.pointcut) {sb.append( || ).append(execution().append(p).append());}// 组合后去除最前面的 || 返回return sb.substring(3);}public void setPointcut(SetString pointcut) {this.pointcut pointcut;} }外部配置切入点示例 由于切入点中有特殊字符*所以需要加入引号单引号或双引号都可以 # 事务切入点 tuwer-transaction:pointcut:- * com.tuwer1231.service..*Impl.*(..))- * com.tuwer.service123..*Impl.*(..))- * com.tuwer345.service123..*Impl.*(..))3 切面自动配置类 package com.tuwer.config;import org.aspectj.lang.annotation.Aspect; import org.springframework.aop.Advisor; import org.springframework.aop.aspectj.AspectJExpressionPointcut; import org.springframework.aop.support.DefaultPointcutAdvisor; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionManager; import org.springframework.transaction.interceptor.DefaultTransactionAttribute; import org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource; import org.springframework.transaction.interceptor.TransactionInterceptor;import javax.annotation.Resource;/*** p事务自动配置类/p** author 土味儿* Date 2023/4/17* version 1.0*/ Aspect Configuration EnableConfigurationProperties(TransactionProperty.class) public class TuwerTransactionAutoConfiguration {/*** 注入 TransactionProperty 属性配置类*/Resourceprivate TransactionProperty transactionProperty;/*** 注入事务管理器*/Resourceprivate TransactionManager transactionManager;/*** 定义事务增强** return*/Beanpublic TransactionInterceptor txAdvice() {NameMatchTransactionAttributeSource source new NameMatchTransactionAttributeSource();// 查询等只读DefaultTransactionAttribute readonlyAttr new DefaultTransactionAttribute();readonlyAttr.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);readonlyAttr.setReadOnly(true);source.addTransactionalMethod(get*, readonlyAttr);source.addTransactionalMethod(select*, readonlyAttr);source.addTransactionalMethod(query*, readonlyAttr);source.addTransactionalMethod(load*, readonlyAttr);source.addTransactionalMethod(search*, readonlyAttr);source.addTransactionalMethod(find*, readonlyAttr);source.addTransactionalMethod(list*, readonlyAttr);source.addTransactionalMethod(count*, readonlyAttr);source.addTransactionalMethod(is*, readonlyAttr);// 增删改DefaultTransactionAttribute otherAttr new DefaultTransactionAttribute();otherAttr.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);source.addTransactionalMethod(*, otherAttr);return new TransactionInterceptor(transactionManager, source);}/*** 织入事务** return*/Beanpublic Advisor txAdviceAdvisor() {// 切入点AspectJExpressionPointcut pointcut new AspectJExpressionPointcut();pointcut.setExpression(transactionProperty.getPointcutExpression());return new DefaultPointcutAdvisor(pointcut, txAdvice());} }4 spring.factories 指明自动配置类的地址在 resources 目录下编写一个自己的 META-INF\spring.factories org.springframework.boot.autoconfigure.EnableAutoConfiguration\com.tuwer.config.TuwerTransactionAutoConfiguration5 Install 把starter安装install到本地maven仓库中 三、使用说明 1、引入starter依赖 !-- 事务starter -- dependencygroupIdcom.tuwer/groupIdartifactIdtuwer-transaction-spring-boot-starter/artifactIdversion1.0-SNAPSHOT/version /dependency2、配置切入点 如果不配置就使用默认的切入点此步骤可以省略。 至此事务配置就OK了
http://www.dnsts.com.cn/news/135378.html

相关文章:

  • 优质的邵阳网站建设益阳市建设网站
  • 做国际黄金看什么网站最流行的网站开发框架
  • 魔站建站系统哪家好做网站接私活流程
  • 企业家网站建设哪个网站有介绍拿到家做的手工活
  • 西安网站建设服务wordpress怎样进入后台
  • 企业建站有哪些步骤新手创业开什么店最好
  • 网站建设从入门pdf进出口贸易网
  • xin网站ftp上传开源众包
  • 金华市住房和城乡建设局网站wordpress即时
  • 木匠手做网站WordPress给分类页面伪静态
  • 阿里云专有网络做网站中山市网站开发外包公司
  • 做网站需要到什么技术上海正规网站建设怎么样
  • 北京网站备案号微分销是什么意思
  • 文化传播集团网站建设成都网站建设开发价
  • 公司网站建设原则seo优化网站快速排名
  • canvas效果网站校园微网站建设
  • 域名 备案 没有网站吗河源市住宅和城乡规划建设局网站
  • 济南网站开发公司排名做网站创业流程图
  • 做斗图网站百度指数网址
  • 网站建设后帐号密码网络培训视频如何加速
  • 010-58813333 可信网站电商网站前端源码
  • 济南家居行业网站开发网络组建与网络资源共享实验报告
  • 恩平市网站建设灯光设计公司排名
  • 甘肃农产品网站建设深圳最新新闻事件头条
  • ae模板下载网站推荐网络平台不能将盈利模式不明朗
  • 怎样做自己的微商网站专做机械零配件的网站
  • wordpress 分享网站wordpress数据统计
  • 做电影网站投资多少钱沈阳网站建设开发
  • 怎么做彩票平台网站创建网站目录应注意
  • 郑州网站建设网站推广温州网站关键词