In this post under Spring Retry, I will show with example how to configure StatisticsListener using interceptor. Below is the complete xml code which shows how to configure StatisticsListener using interceptor. XML Code 1 <?xml version=”1.0″ encoding=”UTF-8″?>2 <beans xmlns=”http://www.springframework.org/schema/beans”3 xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance”4 xmlns:aop = “http://www.springframework.org/schema/aop”5 xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd6 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd”>7 <aop:config>8 <aop:pointcut id=”transactional” expression=”execution(* defaultPackage.Service1.executeWithException(..))”/>9 <aop:advisor pointcut-ref=”transactional” advice-ref=”retryAdvice”/>10…… Continue reading Configuring StatisticsListener (using interceptor)
Category: XML Configuration
Configuring Recovery Callback (using interceptor)
In this post under Spring Retry –> XML Configuration –> Spring AOP, I will show with example how to configure RecoveryCallback using Spring AOP. For our example we will create a recovery class as shown below CustomMethodInvocationRecoverer package defaultPackage; import org.springframework.retry.interceptor.MethodInvocationRecoverer; public class CustomMethodInvocationRecoverer implements MethodInvocationRecoverer<Void> { @Override public Void recover(Object[] args, Throwable cause) {…… Continue reading Configuring Recovery Callback (using interceptor)
Configuring RetryTemplate (using Interceptor)
In the previous post under Spring Retry –> XML Configuration –> Spring AOP, I showed with example how to configure Spring Retry using interceptor. In that post I used RetryOperationsInterceptor class as shown in the below snippet. <bean id=”retryAdvice” class=”org.springframework.retry.interceptor.RetryOperationsInterceptor”/> In the above code snippet, I created a bean of RetryOperationsInterceptor which will create a…… Continue reading Configuring RetryTemplate (using Interceptor)
ExponentialBackOffPolicy Example (using xml configuration)
In this post under Spring Retry, I will introduce with example another out of the box implementation of BackOffPolicy i.e., ExponentialBackOffPolicy. ExponentialBackOffPolicy increases the backoff period at every retry attempt by a specified number. ExponentialBackOffPolicy requires three inputs for it to work, which are1) initialInterval –> the backoff period used at first retry2) maxInterval –>…… Continue reading ExponentialBackOffPolicy Example (using xml configuration)
UniformRandomBackOffPolicy Example (using xml configuration)
In this post under Spring Retry, I will explain with example how to use UniformRandomBackOffPolicy (another implementation of BackOffPolicy interface). UniformRandomBackOffPolicy chooses a random time in ms between user configured MinBackOffPeriod and MaxBackOffPeriod and then before a failed operations is retried, it pauses for that time. Below is the xml configuration code. XML code 1…… Continue reading UniformRandomBackOffPolicy Example (using xml configuration)
FixedBackOffPolicy Simple Example (using xml configuration)
In this post under Spring Retry, I will explain backoff policy concept with example. In Spring Retry, when an operation fails, it is immediately retried but if you want Spring Retry to wait for some time before retrying, you can take help of backoff policies. Backoff policies help us define different policies which will tell…… Continue reading FixedBackOffPolicy Simple Example (using xml configuration)
Combining multiple Retry Policies (using xml)
In this post under Spring Retry, I will show with example how to combine multiple retry policies. Below is the xml configuration XML code 1 <?xml version=”1.0″ encoding=”UTF-8″?> 2 <beans xmlns=”http://www.springframework.org/schema/beans” 3 xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” 4 xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd”> 5 <bean id=”maxAttemptsRetryPolicy1″ class=”org.springframework.retry.policy.MaxAttemptsRetryPolicy”> 6 <property name=”maxAttempts” value=”3″/> 7 </bean> 8 9 <bean id=”maxAttemptsRetryPolicy2″ class=”org.springframework.retry.policy.MaxAttemptsRetryPolicy”> 10 <property name=”maxAttempts” value=”6″/>…… Continue reading Combining multiple Retry Policies (using xml)
Configuring different retry policy for different exceptions (using xml)
In this post under Spring Retry, I will show with example how to configure different retry policy for different exceptions. Till now in all my previous posts, I showed how to configure single retry policy regardless of whatever exception the program throws. For all exceptions, the same retry policy will be followed. But they are…… Continue reading Configuring different retry policy for different exceptions (using xml)
Spring Retry only for specific exceptions and its causes (using xml)
In this post under Spring Retry, I will show with example how to configure SimpleRetryPolicy to retry failed operations for specific exceptions and its causes also. They are situations where exceptions are chained together to indicate Exception1 was caused due to Exception2. So here the cause is Exception2 and the main exception is Exception1. So…… Continue reading Spring Retry only for specific exceptions and its causes (using xml)
Spring Retry only for specific exceptions (using xml configuration)
In this post under Spring Retry, I will show with example how to configure Spring Retry to retry failed operations for specific exceptions only. For this purpose Spring Retry provides out of the box SimpleRetryPolicy class. Below is the xml configuration XML Code 1 <?xml version=”1.0″ encoding=”UTF-8″?> 2 <beans xmlns=”http://www.springframework.org/schema/beans” 3 xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” 4 xsi:schemaLocation=”http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd”>…… Continue reading Spring Retry only for specific exceptions (using xml configuration)