我有这段代码
@Retryable(maxAttempts = 3, stateful = true, include = ServiceUnavailableException.class,
exclude = URISyntaxException.class, backoff = @Backoff(delay = 1000, multiplier = 2) )
public void testThatService(String serviceAccountId)
throws ServiceUnavailableException, URISyntaxException {
//这里有一些实现
}
有没有办法可以使用 @Value 来配置 maxAttempts 、延迟和乘数?
或者是否有其他方法可以使注释中的此类字段可配置?
随着 Spring-retry 1.2 版本的发布,这是可能的。 @Retryable 可以使用 SPEL 进行配置。
@Retryable(
value = { SomeException.class,AnotherException.class },
maxAttemptsExpression = "#{@myBean.getMyProperties('retryCount')}",
backoff = @Backoff(delayExpression = "#{@myBean.getMyProperties('retryInitalInterval')}"))
public void doJob(){
//your code here
}
欲了解更多详情,请参阅:https://github.com/spring-projects/spring-retry/blob/master/README.md https://github.com/spring-projects/spring-retry/blob/master/README.md
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)