从application.properties文件中读取spring @Retryable的maxAttempts [英] Read maxAttempts of spring @Retryable from application.properties file

查看:214
本文介绍了从application.properties文件中读取spring @Retryable的maxAttempts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Retryable(value = Exception.class, maxAttempts = 3)
public Boolean sendMessageService(Request request){
   ...
}

注释中的

maxAttempts参数是硬编码的.我可以从application.properties文件中读取该值吗?

maxAttempts argument in @Retryable annotation is hard coded. Can i read that value from application.properties file?

类似

@Retryable(value = Exception.class, maxAttempts = "${MAX_ATTEMPTS}")

推荐答案

否;使用注释时,无法通过属性进行设置.

No; it's not possible to set via a property when using the annotation.

您可以手动连接RetryOperationsInterceptor bean,并使用Spring AOP将其应用于您的方法...

You can wire up the RetryOperationsInterceptor bean manually and apply it to your method using Spring AOP...

编辑

<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是要应用重试的方法.

Where EchoService.test is the method you want to apply retries to.

这篇关于从application.properties文件中读取spring @Retryable的maxAttempts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆