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

ps做网站的流程网站软件设计

ps做网站的流程,网站软件设计,合肥瑶海区,门户网址一、前言 微服务架构下#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.w-s-a.com/news/996385/

相关文章:

  • 白领兼职做网站贵阳网站设计哪家好
  • 热水器网站建设 中企动力企业网站开发需要多钱
  • 北京市建设工程信息网交易网站静态网页模板免费下载网站
  • 福田欧曼服务站网站前台设计
  • 网站做系统叫什么软件吗注册域名需要实名认证吗
  • jsp网站开发教学视频ui设计风格
  • 注册网站建设开发怎么自己做导航网站
  • 设计做网站品牌咖啡主题网页界面设计
  • 个人网站制作总体设计宿迁房价2023年最新房价
  • 服装网站建设进度及实施过程马鞍山网站设计制作
  • 郑州网站优化顾问济宁网站制作
  • 网站开发简单吗网站引导页分为三个板块设计风格
  • 湖南做网站 在线磐石网络百度一下百度搜索
  • 现在建网站多少钱推广营销费
  • 联想企业网站建设的思路西安网站建设阳建
  • 网站内容 内链网站建设电话销售工作总结
  • 系统网站开发知名的摄影网站有哪些
  • 网站拍照的幕布扬中网站建设价位
  • 网站ie兼容性差西安小程序开发的公司
  • 上海网站建设培训app网站开发成本
  • 个人网站icp外贸网站开发 河南
  • 遵义建设网站无锡市规划建设局网站
  • 海外留学网站建设方案门户网站的发布特点
  • 网站建设不赚钱net112企业建站系统
  • 网站建设团队管理模板贵州省住房和城乡建设部网站
  • 曲沃网站建设网上学编程的有哪些比较好的网站
  • 厦门网站建设慕枫学做网站需要多久
  • 爱奇艺做任务领vip网站设计广告图片
  • 中科汇联网站建设手册上海公司名称注册查询网
  • 网站建设电子商务课总结和体会关于做网站书籍