spring @retryable不生效的一种场景分析
作者:蔚蓝色的风暴
项目中某个位置要调用其它部门的接口,一直有问题,对方让加重试,这篇文章主要介绍了spring @retryable不生效的一种场景分析,感兴趣的朋友跟随小编一起看看吧
项目中某个位置要调用其它部门的接口,一直有问题,对方让加重试。使用@Retryable之后发现并没有进行重试,之前其它接口都正常重试了。
经过研究发现了这个方法是直接写在调用的类里面的,这种情况重试竟然不会进行。
在某个方法中调用另一个带retryable的方法时,如果这个retry方法在同一个类中,不会进行重试
执行methodA 不会重试
public class TaskSubSchedule {
public void methodA() {
System.out.println("开始测试");
methodB();
}
@Retryable(value = RuntimeException.class,maxAttempts = 5)
public void methodB() {
System.out.println("我是方法B");
throw new RuntimeException();
}
}会重试
public class TaskSubSchedule {
@Autowired
private CiserviceImpl ciService;
public void methodA() {
System.out.println("开始测试");
ciService.methodB();
}
public class CiServiceImpl {
@Retryable(value = RuntimeException.class,maxAttempts = 5)
public void methodB() {
System.out.println("我是方法B");
throw new RuntimeException();
}
}
}到此这篇关于spring @retryable不生效的一种场景的文章就介绍到这了,更多相关spring @retryable不生效内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
