项目中某个位置要调用其它部门的接口,一直有问题,对方让加重试。使用@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();
}
}
}
168万+





