java – 如何使spring @retryable可配置?

我有这段代码
@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是您要应用重试的方法.

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...