小编Aez*_*zio的帖子

Spring-Retry在实现接口时无法定位恢复方法

我在用 spring boot 做 spring-retry 时发现了一个问题。类实现接口时,超过最大重试次数后无法进入@recover方法。但是当我注入一个普通的类时,我可以进入这个方法。您的及时帮助和善意的建议将不胜感激,谢谢!

当我这样做时,我可以进入@Recover 方法

@Service
public class TestService {

    @Retryable(Exception.class)
    public String retry(String c) throws Exception{
        throw new Exception();
    }

    @Recover
    public String recover(Exception e,String c) throws Exception{
        System.out.println("got error");
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

但是一旦类实现了另一个接口,它就不起作用了

@Service
public class TestService implements TestServiceI{

    @Override
    @Retryable(Exception.class)
    public String retry(String c) throws Exception{
        throw new Exception();
    }

    @Recover
    public String recover(Exception e,String c) throws Exception{
        System.out.println("got error");
        return null;
    }
}
Run Code Online (Sandbox Code Playgroud)

java spring spring-retry spring-boot

4
推荐指数
1
解决办法
4335
查看次数

标签 统计

java ×1

spring ×1

spring-boot ×1

spring-retry ×1