且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在Spring bean的基类中定义的方法中使用@Retryable不会重试

更新时间:2023-10-06 13:20:52

@Retryable使用仅可重试方法的外部调用通过代理(在RetryTemplate中调用该方法);类中的内部调用会绕过代理,因此不会重试.

Only external calls to retryable methods go through the proxy (which invokes the method within a RetryTemplate); internal calls within the class bypass the proxy and therefore are not retried.

您可以玩一些技巧从应用程序上下文中获取对代理的引用并进行调用,或者直接在您的doStuff()方法中直接使用RetryTemplate.

You can play some tricks to get a reference to the proxy from the application context and call that, or simply use a RetryTemplate directly within your doStuff() method.