spring-retry :“上次尝试后重试已耗尽,没有恢复路径”不可重试方法的原始异常

发布于 2025-01-15 10:48:01 字数 779 浏览 4 评论 0原文

我正在尝试在我的 Spring Boot 应用程序中实现 spring-retry(版本 - 1.3.1)。如果在第一个请求中找不到记录,我必须重试 Web 服务操作来读取记录。

示例代码:

@Retryable(include = {IllegalArgumentException.class}, backoff = @Backoff(500), maxAttempts = 3, recover ="readFallback")
Object read(String Id);

@Recover
Object readFallback(RuntimeException e, String Id);

void deletePayment(String paymentId);

问题: 在异常情况下,我从读取方法(用 @Retryable 注释)中得到正确的响应,但当我在删除方法上遇到异常时,我得到带有嵌套原始异常的 RetryExhaustedException 。如您所见,删除方法没有用 @Retryable 注释。删除方法在不同的包中。

**异常响应示例 **:“上次尝试后重试已用尽,没有恢复路径;嵌套异常为异常。NotFoundException:未找到”

预期:删除方法不应受到 @Retryable 的影响。有人可以帮我找出我错过了什么或做错了什么吗?我已经尝试过,但无法在互联网上找到这个问题的解决方案。

提前致谢 !

I am trying to implement spring-retry(version - 1.3.1) in my spring boot application. I have to retry webservice operation to read the record if not found in first request.

sample code:

@Retryable(include = {IllegalArgumentException.class}, backoff = @Backoff(500), maxAttempts = 3, recover ="readFallback")
Object read(String Id);

@Recover
Object readFallback(RuntimeException e, String Id);

void deletePayment(String paymentId);

Problem :
I am getting correct response from read method(annotated with @Retryable) in exception scenario but I am getting RetryExhaustedException with nested original exception when I am getting exception on my delete method. As you see, delete method doesn't annotated with @Retryable . Delete method is in different package.

**Sample exception response ** : "Retry exhausted after last attempt with no recovery path; nested exception is exception.NotFoundException: Not found"

Expected : Delete method should not be impacted by @Retryable. Can someone help me to find what am i missing or doing wrong. I have tried but unable to not found the solution of this problem on internet.

Thanks in advance !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屋顶上的小猫咪 2025-01-22 10:48:01

按我的预期工作:

@SpringBootApplication
@EnableRetry
public class So71546747Application {

    public static void main(String[] args) {
        SpringApplication.run(So71546747Application.class, args);
    }

    @Bean
    ApplicationRunner runner(SomeRetryables retrier) {
        return args -> {
            retrier.foo("testFoo");
            try {
                Thread.sleep(1000);
                retrier.bar("testBar");
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        };
    }

}

@Component
class SomeRetryables {

    @Retryable
    void foo(String in) {
        System.out.println(in);
        throw new RuntimeException(in);
    }

    @Recover
    void recover(String in, Exception ex) {
        System.out.println("recovered");
    }

    void bar(String in) {
        System.out.println(in);
        throw new RuntimeException(in);
    }

}
testFoo
testFoo
testFoo
recovered
testBar
java.lang.RuntimeException: testBar
    at com.example.demo.SomeRetryables.bar(So71546747Application.java:52)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:789)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753)
    at org.springframework.retry.annotation.AnnotationAwareRetryOperationsInterceptor.invoke(AnnotationAwareRetryOperationsInterceptor.java:166)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:698)
    at com.example.demo.SomeRetryables$EnhancerBySpringCGLIB$e61dd199.bar(<generated>)
    at com.example.demo.So71546747Application.lambda$0(So71546747Application.java:26)
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:768)
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:758)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:310)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
    at com.example.demo.So71546747Application.main(So71546747Application.java:17)

请提供一个 MCRE 来展示您所看到的行为,以便我们了解问题所在。

Works as expected for me:

@SpringBootApplication
@EnableRetry
public class So71546747Application {

    public static void main(String[] args) {
        SpringApplication.run(So71546747Application.class, args);
    }

    @Bean
    ApplicationRunner runner(SomeRetryables retrier) {
        return args -> {
            retrier.foo("testFoo");
            try {
                Thread.sleep(1000);
                retrier.bar("testBar");
            }
            catch (Exception e) {
                e.printStackTrace();
            }
        };
    }

}

@Component
class SomeRetryables {

    @Retryable
    void foo(String in) {
        System.out.println(in);
        throw new RuntimeException(in);
    }

    @Recover
    void recover(String in, Exception ex) {
        System.out.println("recovered");
    }

    void bar(String in) {
        System.out.println(in);
        throw new RuntimeException(in);
    }

}
testFoo
testFoo
testFoo
recovered
testBar
java.lang.RuntimeException: testBar
    at com.example.demo.SomeRetryables.bar(So71546747Application.java:52)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:789)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753)
    at org.springframework.retry.annotation.AnnotationAwareRetryOperationsInterceptor.invoke(AnnotationAwareRetryOperationsInterceptor.java:166)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:753)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:698)
    at com.example.demo.SomeRetryables$EnhancerBySpringCGLIB$e61dd199.bar(<generated>)
    at com.example.demo.So71546747Application.lambda$0(So71546747Application.java:26)
    at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:768)
    at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:758)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:310)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1312)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1301)
    at com.example.demo.So71546747Application.main(So71546747Application.java:17)

Please provide an MCRE that exhibits the behavior you see so we can see what's wrong.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文