<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>com</groupId>
<artifactId>test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging> <name>test</name>
<url>http://maven.apache.org</url> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
<relativePath/>
</parent> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.retry</groupId>
<artifactId>spring-retry</artifactId>
</dependency> <dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
</dependencies> <!-- Package as an executable jar -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build> </project>
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.retry.annotation.EnableRetry; @SpringBootApplication
@EnableRetry
public class Application { public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; @RestController
public class TestController { @Autowired
private RemoteService remoteService; @RequestMapping("/show")
public String show() {
try {
remoteService.call();
} catch (Exception e) {
// TODO Auto-generated catch block
System.out.println("Exception Occur" + e.getMessage());
}
return "Hello World";
}
}
import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service; @Service
public class RemoteService { private final int MAXATTEMPTS = 2;
private final long DELAY = 1000L; @Retryable(value = {NullPointerException.class, ArithmeticException.class},
maxAttempts = MAXATTEMPTS, backoff = @Backoff(delay = DELAY, multiplier = 1))
public void call() throws Exception {
System.out.println("do something...");
int a = 5 / 0;
String.valueOf(null);
// throw new NullPointerException("RPC调用异常");
} @Recover
public void recover(Exception e) {
e.printStackTrace();
}
}

spring retry注解的更多相关文章

  1. Spring retry基本使用

    Spring retry基本使用 背景介绍 在实际工作过程中,重试是一个经常使用的手段.比如MQ发送消息失败,会采取重试手段,比如工程中使用RPC请求外部服务,可能因为网络 波动出现超时而采取重试手段 ...

  2. Spring Retry

    最近组内准备将项目中原有的重试功能抽取出来重构为一个重试平台,由于对重试的功能要求比较高,采用了不少中间件和框架(jimdb,jproxy, Elastic-Job ,JMQ,Hbase, Disru ...

  3. Spring retry实践

    在开发中,重试是一个经常使用的手段.比如MQ发送消息失败,会采取重试手段,比如工程中使用RPC请求外部服务,可能因为网络波动出现超时而采取重试手段......可以看见重试操作是非常常见的一种处理问题, ...

  4. Spring异常重试框架Spring Retry

    Spring Retry支持集成到Spring或者Spring Boot项目中,而它支持AOP的切面注入写法,所以在引入时必须引入aspectjweaver.jar包. 快速集成的代码样例: @Con ...

  5. 异常重试框架Spring Retry实践

    前期准备在Maven项目中添加Spring Retry和切面的依赖 POM: <!-- Spring Retry --> <dependency> <groupId> ...

  6. Spring框架中一个有用的小组件:Spring Retry

    1.概述 Spring Retry 是Spring框架中的一个组件, 它提供了自动重新调用失败操作的能力.这在错误可能是暂时发生的(如瞬时网络故障)的情况下很有帮助. 在本文中,我们将看到使用Spri ...

  7. Spring Retry 在SpringBoot 中的应用

    Spring Boot中使用Spring-Retry重试框架 Spring Retry提供了自动重新调用失败的操作的功能.这在错误可能是暂时的(例如瞬时网络故障)的情况下很有用. 从2.2.0版本开始 ...

  8. Spring Retry 重试

    重试的使用场景比较多,比如调用远程服务时,由于网络或者服务端响应慢导致调用超时,此时可以多重试几次.用定时任务也可以实现重试的效果,但比较麻烦,用Spring Retry的话一个注解搞定所有.话不多说 ...

  9. Spring MVC注解的一些案列

    1.  spring MVC-annotation(注解)的配置文件ApplicationContext.xml <?xml version="1.0" encoding=& ...

随机推荐

  1. 1147. Heaps (30)

    In computer science, a heap is a specialized tree-based data structure that satisfies the heap prope ...

  2. C#实现根据传入时间段,找出时间段内日期,并生成相对应文件路径

    [1]获取固定日期范围内的所有日期,以数组形式返回 /// <summary>        /// 获取固定日期范围内的所有日期,以数组形式返回        /// </summ ...

  3. Azure上部署Barracuda WAF集群 --- 1

    公有云上的第一层防护,一般要采用Proxy模式的安全设备. 梭子鱼的WAF是最早支持Azure China公有云的安全设备. 本文记录了在Azure上安装部署Barracuda的过程.下面就是安装部署 ...

  4. [转] 更新Flash CS6发布设置的目标播放器版本

    目前Aodbe发布的最新版的Flash CS6,都不支持将Flash Player 11作为目标播放器版本发布.这个问题很容易解决,但涉及到的东西却比较多,我在这里将一一讲解.首先来个Setp by ...

  5. IPC的使用

    IPC,Inter-Processor Communication是SYS/BIOS处理核间通信的组件: IPC的几种应用方式: 1.最小使用(Minimal use) 这种情况是通过核间的通知机制( ...

  6. 关于使用C# 启动msi失败的问题

    原以为在启动msi是件小儿科的事,上代码: ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = "C:\\myTest ...

  7. Nmon工具的使用以及通过nmon_analyse生成分析报表

    在我们监控我们的操作系统的时候如果可以把各个硬件的监控信息生成形象化的分析报表图对于我们来说是件太好的事情了,而通过ibm的nom和nmon_analyser两者的结合完全可以实现我们的要求.首先对n ...

  8. arm-linux-3.4.2移植for2440

    ----------------------------2440 上内核3.4.2移植------------------------ PS:因wifi项目中无wifi驱动,需新内核. 1.首先在内核 ...

  9. 关于startactivity初始化activity的过程以及activity和window以及view的关系

    activity 构造一个实现了window的phonewindow,获得viewroot,然后往里面加入view 当发生事件的时候,如KEYDOWN,windowmanagerservice就接受到 ...

  10. leetcode-002

    给定两个非空链表来表示两个非负整数.位数按照逆序方式存储,它们的每个节点只存储单个数字.将两数相加返回一个新的链表. 你可以假设除了数字 0 之外,这两个数字都不会以零开头. 示例: 输入:(2 -& ...