项目中某个位置要调用其它部门的接口,一直有问题,对方让加重试。使用@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不生效内容请搜索3w代码以前的文章或继续浏览下面的相关文章希望大家以后多多支持3w代码!
发表评论