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

火速网站建设广州微网站建设哪家好

火速网站建设,广州微网站建设哪家好,天津优化加盟,计算机网络技术课程SpringBoot 整合Spring-Retry可以实现错误重试 目录引入依赖开启spring-retry使用重试注解Retryable 注解Backoff 注解测试参考引入依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-aop/artifactI…SpringBoot 整合Spring-Retry可以实现错误重试 目录引入依赖开启spring-retry使用重试注解Retryable 注解Backoff 注解测试参考引入依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-aop/artifactId /dependency dependencygroupIdorg.springframework.retry/groupIdartifactIdspring-retry/artifactId /dependency完整依赖pom.xml ?xml version1.0 encodingUTF-8? project xmlnshttp://maven.apache.org/POM/4.0.0 xmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexsi:schemaLocationhttp://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsdmodelVersion4.0.0/modelVersionparentgroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-parent/artifactIdversion2.7.7/versionrelativePath/ !-- lookup parent from repository --/parentgroupIdcom.example/groupIdartifactIddemo/artifactIdversion0.0.1-SNAPSHOT/versionnamedemo/namedescriptionDemo project for Spring Boot/descriptionpropertiesjava.version1.8/java.version/propertiesdependenciesdependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-web/artifactId/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-devtools/artifactIdscoperuntime/scopeoptionaltrue/optional/dependencydependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdoptionaltrue/optional/dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdscopetest/scope/dependency!-- spring-retry --dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-aop/artifactId/dependencydependencygroupIdorg.springframework.retry/groupIdartifactIdspring-retry/artifactId/dependency/dependenciesbuildpluginsplugingroupIdorg.springframework.boot/groupIdartifactIdspring-boot-maven-plugin/artifactIdconfigurationexcludesexcludegroupIdorg.projectlombok/groupIdartifactIdlombok/artifactId/exclude/excludes/configuration/plugin/plugins/build/project开启spring-retry 启动类上增加注解 EnableRetry package com.example.demo;import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.retry.annotation.EnableRetry;EnableRetry SpringBootApplication public class Application {public static void main(String[] args) {SpringApplication.run(Application.class, args);}} 使用重试注解 Retryable 注解 value可重试的异常类型。含义同include。默认为空(如果excludes也为空则重试所有异常)include可重试的异常类型。默认为空(如果excludes也为空则重试所有异常)exclude无需重试的异常类型。默认为空(如果includes也为空则重试所有异常)maxAttempts最大重试次数(包括第一次失败)默认为3次backoff重试等待策略,下面会在Backoff中介绍recover表示重试次数到达最大重试次数后的回调方法 Backoff 注解 delay重试之间的等待时间(以毫秒为单位)maxDelay重试之间的最大等待时间(以毫秒为单位)multiplier指定延迟的倍数delayExpression重试之间的等待时间表达式maxDelayExpression重试之间的最大等待时间表达式multiplierExpression指定延迟的倍数表达式random随机指定延迟时间 使用示例 package com.example.demo.component;import org.springframework.retry.annotation.Recover; import org.springframework.retry.annotation.Retryable; import org.springframework.stereotype.Component;Component public class HttpRequest {private int count 0;/*** 模拟网络请求异常* return*/Retryable(recover errorHandler)public String getResponse() {count;System.out.println(time: count);if (count 4) {throw new RuntimeException(count: count);}return success;}/*** 错误处理函数* 注意需要返回 String否则会抛出方法找不到异常* org.springframework.retry.ExhaustedRetryException: Cannot locate recovery method** param e* return*/Recoverpublic String errorHandler(RuntimeException e) {System.out.println(errorHandler);return ok;} } 测试 package com.example.demo.component;import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest;SpringBootTest public class HttpRequestTest {Autowiredprivate HttpRequest httpRequest;Testpublic void getResponse(){httpRequest.getResponse();} } 输出结果 time: 1 time: 2 time: 3 errorHandler参考 SpringBoot 中使用 spring-retry 轻松解决重试
http://www.dnsts.com.cn/news/68633.html

相关文章:

  • 网站后台演示娱乐建网站
  • 有没有做产品团购的网站ps网站首页效果图实例
  • 英国网站建设哪个网站做任务给东西
  • 水产食品企业网站模板莱芜金点子广告电子版2022最新
  • 江山建设工程信息网站优化网站关键词排名软件
  • 合肥企业网站推广网站设计三把火
  • 建设快三网站南山做网站哪家专业
  • 企业建立网站账户如何做手机网站源代码
  • 宣城网站开发企业网站建设的价格
  • 网站建设云解析dns有什么用广州市专注网站建设品牌
  • 织梦仿asp网站做网站公司属于什么行业
  • 电子商务网站建设与维护的主要内容wordpress输出标签下文章
  • 网站策划与维护电子商务网站建设与运营
  • 济南网站制作公司排名邯郸住房和城乡建设局网站
  • 网站搭建 保定免费的html
  • 做综合类网站好不好合肥市住房和城乡建设厅网站
  • dw怎样做网站切换最新推广注册app拿佣金
  • 网站赚钱厦门网站建设手机
  • 建行网站会员有什么用论坛推广的步骤
  • 温州网站建站模板wordpress 安装 godaddy在哪里 上传的根目录
  • 高校网站建设意义品牌ip形象设计
  • 设计公司网站公司详情做游戏推广怎么找客户
  • 光速网络网站网站开发视频资源放哪儿
  • 网站的标题符号十大软件公司
  • 做果蔬行业的网站网站开发的基本过程
  • 嘉定建站公司衡水做网站推广的公司
  • 淘宝做网站为什么那么便宜网站设计公司产品介绍
  • 备份wordpress配置番禺网站优化
  • 英文网站建设风格特点网站优化设计公司
  • 负面信息搜索引擎 网站搭建wordpress步骤