<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();
}
}

最新文章

  1. Android Studio使用技巧:导出jar包
  2. 让Delphi的DataSnap发挥最大效率
  3. .net自定义事件,经典简单实例代码
  4. 说Win7激活
  5. C语言中字符型和字符串型的区别?
  6. [LeetCode#157] Read N Characters Given Read4
  7. JavaScript split()
  8. angularJS使用$watch监控数据模型的变化
  9. 【linux驱动笔记】linux模块机制浅析
  10. PHP的高并发和大数据处理
  11. 一个编程菜鸟的进阶之路(C/C++)
  12. 156个Python网络爬虫资源
  13. SQL注入之Sqli-labs系列第四十六关(ORDER BY注入)
  14. SQL问题+知识点总结总
  15. 在Pandas中更改列的数据类型【方法总结】
  16. 本机spark 消费kafka失败(无法连接)
  17. vsftp在防火墙开启需要开放的端口
  18. Go第一篇之轻松入门
  19. 跨域资源共享/option 请求产生原因
  20. 十四、ReentrantLock重入锁

热门文章

  1. bzoj 2093 [Poi2010]Frog——滑动窗口
  2. spring IOC 注解@Resource
  3. Poj 2350 Above Average(精度控制)
  4. centos7 查看启动ntp服务命令
  5. JS中数组方法小总结
  6. java.util.Date、java.sql.Date、java.sql.Time、java.sql.Timestamp区别和联系
  7. python+selenium UI自动化不同浏览器之间的切换
  8. kafka之c接口常用API------librdkafka
  9. Struts2学习第六课 实现登录登出功能
  10. 关于export环境变量生存期