Java – how to make spring @ retryable configurable?
•
Java
I have this code
@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 {
//Here are some implementations}
Is there any way to use @ value to configure maxattempts, delays and multipliers? Or is there any other way to make these fields in comments configurable?
Solution
Not yet possible; To connect in a property, the annotation must be changed to get the string value, and the annotation bean post processor must parse placeholders and / or spiel expressions
For alternatives, see this answer, but it cannot be completed by annotation at present
edit
<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>
Where echoservice Test is the method you want to apply retry
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
