I encounter this problem too. that's what i solved it:
Because spring-amqp wrap business exceptions into ListenerExecutionFailedException, So we register wrapped business exceptions instead of throwed ListenerExecutionFailedException itself.
Code:
public class CustomRetryPolicy extends SimpleRetryPolicy {
public CustomRetryPolicy() {
super();
}
public CustomRetryPolicy(int maxAttempts,
Map<Class<? extends Throwable>, Boolean> retryableExceptions) {
super(maxAttempts, retryableExceptions);
}
@Override
public void registerThrowable(RetryContext context, Throwable throwable) {
super.registerThrowable(context, throwable!=null && throwable.getCause()!=null ? throwable.getCause() : throwable);
}
}
Config of retryTemplate:
Code:
<bean id="retryTemplate" class="org.springframework.retry.support.RetryTemplate">
<property name="backOffPolicy">
<bean class="org.springframework.retry.backoff.FixedBackOffPolicy">
<property name="backOffPeriod" value="10000" />
</bean>
</property>
<property name="retryPolicy">
<bean class="com.xxx.email.service.message.impl.CustomRetryPolicy">
<constructor-arg name="maxAttempts" value="3" />
<constructor-arg name="retryableExceptions" ref="retryableExceptions" />
</bean>
</property>
</bean>
<util:map id="retryableExceptions" map-class="java.util.HashMap" >
<entry key="com.xxx.email.service.message.exception.SMTPException" value="true" />
</util:map>
that's work fine for me.