首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring-retry @Recover方法仅适用于接口定义。

Spring-retry @Recover方法仅适用于接口定义。
EN

Stack Overflow用户
提问于 2018-10-11 16:36:15
回答 1查看 1.4K关注 0票数 0

我使用spring-retry为我的业务逻辑提供重试策略。我有接口和实现它的服务

代码语言:javascript
复制
public interface MyInterface {
    @Retryable(maxAttempts = 5, backoff = @Backoff(value = 0L))
    void doSth() throws Exception;

    @Recover
    void recoverIfFailed(Exception e);
}

@Service
public class MyService implements MyInterface {
    public void doSth() throws Exception {
            throw new Exception();
    }

    public void recoverIfFailed(Exception e) {
        System.out.println("Recovered!");
    }
}

在这种配置中,一切正常工作。但是,我不明白为什么不能像这样将@Recovery注释移到接口实现上:

代码语言:javascript
复制
@Service
public class MyService implements MyInterface {
    @Retryable(maxAttempts = 5, backoff = @Backoff(value = 0L)) // -- this is working
    public void doSth() throws Exception {
            throw new Exception();
    }

    @Recover // -- this is not working!
    public void recoverIfFailed(Exception e) {
        System.out.println("Recovered!");
    }
}

我真的不想在接口中公开我的恢复方法(因为它似乎是我的内部逻辑),但由于这个问题,我不能。有人能告诉我什么是问题吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-11 17:12:58

我提交了一个打开拉请求以修复此问题

作为一种解决方案,使用@EnableRetry(proxyTargetClass = true)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52765023

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档