首页 > 解决方案 > spring 使用请求中的自定义布尔值重试

问题描述

我是春季注释和春季重试的新手。下面是示例代码,我的查询是基于方法参数isRetryNeeded,我需要决定是否需要重试(这里3次)。谢谢

package com.example.retry;

import org.springframework.retry.annotation.Backoff;
import org.springframework.retry.annotation.Recover;
import org.springframework.retry.annotation.Retryable;

public interface BackendAdapter {

    @Retryable(value = { RemoteServiceNotAvailableException.class }, maxAttempts = 3, backoff = @Backoff(delay = 1000))
    public String getBackendResponse(boolean isRetryNeeded, boolean simulateretryfallback);

    @Recover
    public String getBackendResponseFallback(RuntimeException e);

}

标签: spring-retry

解决方案


没有内置的支持。

但是,由于您的重试是有条件的,RemoteServiceNotAvailableException只需抛出一些其他异常 if isRetryNeededis false


推荐阅读