学无先后,达者为师

网站首页 编程语言 正文

spring @retryable不生效的一种场景

作者:蔚蓝色的风暴 更新时间: 2024-07-18 编程语言

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

原文链接:https://blog.csdn.net/qq_37831759/article/details/140489092

  • 上一篇:没有了
  • 下一篇:没有了
栏目分类
最近更新