java – 如何使spring @retryable可配置?
发布时间:2020-09-18 20:20:39 所属栏目:Java 来源:互联网
导读:我有这段代码 @Retryable(maxAttempts = 3, stateful = true, include = ServiceUnavailableException.class, exclude = URISyntaxException.class, backoff = @Backoff(delay = 1000, multiplier = 2) )public v
|
我有这段代码 @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,延迟和乘数? 解决方法目前还不可能;要在属性中连接,必须更改注释以获取字符串值,并且注释bean后处理器必须解析占位符和/或SpEL表达式.有关替代方法,请参阅this answer,但目前无法通过注释完成. 编辑 <bean id="retryAdvice" class="org.springframework.retry.interceptor.RetryOperationsInterceptor">
<property name="retryOperations">
<bean class="org.springframework.retry.support.RetryTemplate">
<property name="retryPolicy">
<bean class="org.springframework.retry.policy.SimpleRetryPolicy">
<property name="maxAttempts" value="${max.attempts}" />
</bean>
</property>
<property name="backOffPolicy">
<bean class="org.springframework.retry.backoff.ExponentialBackOffPolicy">
<property name="initialInterval" value="${delay}" />
<property name="multiplier" value="${multiplier}" />
</bean>
</property>
</bean>
</property>
</bean>
<aop:config>
<aop:pointcut id="retries"
expression="execution(* org..EchoService.test(..))" />
<aop:advisor pointcut-ref="retries" advice-ref="retryAdvice"
order="-1" />
</aop:config>
其中EchoService.test是您要应用重试的方法. (编辑:鄂州站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
