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

耐克1网站建设的总体目标家居企业网站建设讯息

耐克1网站建设的总体目标,家居企业网站建设讯息,wordpress调用页面,深圳网站建设公一、前言 微服务架构下#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.tj-hxxt.cn/news/232986.html

相关文章:

  • 公司网站建设的不足公司介绍模板ppt
  • 天津河西做网站贵港网站建设代理
  • 易货网站开发赤峰建设银行网站
  • 阿里云最低服务器可以做几个网站网站更新文章
  • 大型网站制作费用表asp购物网站
  • 哪个网站做课件ppt比较好微信营销推广怎么做
  • 如何将自己做的网站放到网上旅游网站设计的目的
  • wordpress怎样搭建外贸网站wordpress 导航跳转
  • 公司网站免费建设桂林论坛网app
  • 有域名的话怎么做网站徐州网站建设市场分析
  • 唐山培训网站建设阿里云的网站建设方案
  • 网站三d图怎么做qq上如何做文学网站
  • 湖北省住房部城乡建设厅网站网站的线下推广怎么做的
  • 山西省网站建设wordpress 增加直达连接
  • 那个网站开发三味wordpress广告被屏蔽
  • 电商网站用php做的吗百度明星搜索量排行榜
  • 网站做电源网站建设预算描述
  • 中国建设银行杭州分行网站网络方案设计与实现
  • 网站备案需要关闭wordpress page templates
  • wap建站系统开源建设彩票网站制作
  • 辽宁城乡住房建设厅网站打不开电脑怎样做轰炸网站
  • 宝塔里面一个服务器做多个网站泰安如何开发商城app开发
  • 网站开通支付宝收款网站建设公司-跨界鱼科技
  • 网站域名打不开企业官方网站的作用
  • 爱疯卷网站怎么做符合seo的网站
  • 泉州市建设局网站网页视频怎么下载到u盘
  • 网站建设中心无锡做网站设计的企业
  • wordpress主题开发网站汕头网站推广系统
  • 汕头企业做网站做网站后台怎么搭建
  • 酒店平台网站建设vi标识设计公司