java – 如何使spring @retryable可配置?
发布时间:2020-09-16 11:02:09 所属栏目: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是您要应用重试的方法. (编辑:鲜蔬坊站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- java – Spring MVC 3.0:String是@PathVariable的首选类型
- Spring整合Quartz实现定时任务调度的方法
- 详解Java正则表达式中Pattern类和Matcher类
- servlet简单实现文件下载的方法
- java实现把对象数组通过excel方式导出的功能
- java判定数组或集合是否存在某个元素的实例
- java – Magento Rest“Admin role not found”错误
- Mybatis返回int或者Integer类型报错的解决办法
- java – Spring Data Rest:RepositoryEventHandler方法未被
- java – 从代码合并两个.odt文件
