从application.properties文件中读取spring @Retryable的maxAttempts [英] Read maxAttempts of spring @Retryable from application.properties file
问题描述
@Retryable(value = Exception.class, maxAttempts = 3)
public Boolean sendMessageService(Request request){
...
}
maxAttempts参数是硬编码的.我可以从 maxAttempts argument in 类似
否;使用注释时,无法通过属性进行设置. No; it's not possible to set via a property when using the annotation. 您可以手动连接 You can wire up the 编辑 Where 这篇关于从application.properties文件中读取spring @Retryable的maxAttempts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!application.properties
文件中读取该值吗?@Retryable
annotation is hard coded. Can i read that value from application.properties
file?@Retryable(value = Exception.class, maxAttempts = "${MAX_ATTEMPTS}")
推荐答案
RetryOperationsInterceptor
bean,并使用Spring AOP将其应用于您的方法... 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
是要应用重试的方法.EchoService.test
is the method you want to apply retries to.