- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我有这段代码
@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 {
//这里的一些实现}
有没有一种方法可以使 maxAttempts 、 delay 和 multiplier 使用 @Value 进行配置?或者有没有其他方法可以使注释中的这些字段可配置?
最佳答案
随着 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
关于java - 如何使 spring @retryable 可配置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38088449/
我使用了spring @Retryable来实现在使用RestTemplate调用其他服务出现问题时重试函数调用。 该函数如下所示,问题是我已将 maxAttempts 设置为 4,以防发生任何异常,
我使用 compile 'org.springframework.retry:spring-retry:1.2.2.RELEASE' 和 Spring Boot 1.5.9.RELEASE。 配置为重
这个问题已经有答案了: Using @Retryable in methods define in spring bean's base class are not retried (1 个回答) 已
spring-retry模块支持方法和类、接口、枚举级别的重试 方式很简单,引入pom包 ?
在我的 SpringBoot 应用程序中,我有一个客户端,它可以发送一个 POST 请求。在 POST 期间,它可能有几个异常(exception)。 如果出现 2 个不同的异常,我想有一个重试逻辑。
我已经阅读了很多有关该主题的内容,但不知何故无法使我的代码正常工作。我有一个非常简单的项目,我正在尝试实现 spring-retry 流程。这是我的主要应用程序类: @EnableRetry @Spr
我已将 @Retryable 放在接口(interface)方法上,现在我需要包含多个异常才能重试。 代码: @Retryable(interceptor = "someRetryIntercept
是否可以根据特定条件重试?如果我用 Retryable 注释,它将根据一些异常重试,但如果捕获到该异常并且满足相应条件,我想重试。示例: @Retryable(value={MyException.c
我在 @Service 类中的方法上使用了 @Retryable 注释 @Service @EnableRetry public class PushService { @Retryable(
以下代码不会重试。我错过了什么? @EnableRetry @SpringBootApplication public class App implements CommandLineRunner {
我正在使用基于注释的方法 - @Retryable 在 Spring Boot 应用程序中进行重试。 @Retryable(value = {DataAccessException.class, Jp
当我运行单元测试时,我希望 thisFails() 方法重试 3 次,然后我希望看到打印恢复记录器行,但它只尝试一次,然后抛出异常。底部的输出是我运行测试后的输出。 我错过了什么? 请随意忽略此部分,
我刚刚使用@Retryable 注释设置了最简单的Spring 应用程序。 @Service public class MyRestService { @Autowired priva
我有这段代码 @Retryable(maxAttempts = 3, stateful = true, include = ServiceUnavailableException.class,
我正在尝试实现重试逻辑。我的代码按预期工作,直到重试方法的返回类型无效。当我将其更改为 String 时,@Recover 停止工作。 @Component public class Adapt
我正在尝试使用 Springs @Retryable 使我的服务方法在失败时重试。 @Retryable(backoff = @Backoff(delay = 1000), maxAttempts =
我在 SpringBatch 的库依赖项中使用带有 @Retryable 注释的 Spring Retry 1.2.4。 在 exceptionExpression 属性中,我指定了一个自定义异常的表
下面的@Retryable 代码适用于直接调用方法的地方,但是通过@Async 注释方法调用可重试方法然后抛出异常。 有什么建议 ? 这是我的服务类 @Service public class Ret
我使用 AnnotationConfigApplicationContext 创建了一个基于 spring 框架的应用程序。 一个 bean 有一个 init 方法,它创建到外部服务的连接。这可以用
这个问题在这里已经有了答案: Using @Retryable in methods define in spring bean's base class are not retried (1 个回
我是一名优秀的程序员,十分优秀!