title: Spring annotation @Retryable - how to set an interceptor
body: <p>I am using a <code>@Retryable</code> annotation on a method in a <code>@Service</code>class</p>
  
  <pre><code>@Service
  @EnableRetry 
  public class PushService {
  
      @Retryable(maxAttempts=5)
      public Result pushIt(myMessage messageIn) {
          ...
      }
  }
  </code></pre>
  
  <p>and it works like a charme: I am getting a message directly from RabbitMQ, it is not acknowledged until either there is no error, or the number of attempts reach 5, and at that time the messages goes straight to the DLQ, right as I wanted.</p>
  
  <p>My only problem is that I need to set the maxAttempts dynamically, from a property file. The solution should be setting an interceptor, but the only fact of having one causes an error, for example when I have :</p>
  
  <pre><code>@Service
  @EnableRetry 
  public class PushService {
  
      @Retryable(interceptor="myInterceptor") 
      public Result pushIt(myMessage messageIn) {
          ...
      }
  }
  </code></pre>
  
  <p>where myInterceptor is defined as :</p>
  
  <pre><code>@Bean
  public StatefulRetryOperationsInterceptor myInterceptor() {
      return RetryInterceptorBuilder.stateful().maxAttempts(5).build();
  }
  </code></pre>
  
  <p>I get an infinite loop with the following exception:</p>
  
  <pre><code>2015-04-08 07:12:10,970 GMT [SimpleAsyncTaskExecutor-1] (ConditionalRejectingErrorHandler.java:67) WARN  listener.ConditionalRejectingErrorHandler: Execution of Rabbit message listener failed.
  org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Listener threw exception
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.wrapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:864)
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:802)
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:690)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$001(SimpleMessageListenerContainer.java:82)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$1.invokeListener(SimpleMessageListenerContainer.java:167)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.invokeListener(SimpleMessageListenerContainer.java:1241)
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:660)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:1005)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:989)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$700(SimpleMessageListenerContainer.java:82)
      at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1103)
      at java.lang.Thread.run(Thread.java:745)
  Caused by: java.lang.ArrayIndexOutOfBoundsException: 1
      at org.springframework.amqp.rabbit.config.StatefulRetryOperationsInterceptorFactoryBean$3.getKey(StatefulRetryOperationsInterceptorFactoryBean.java:103)
      at org.springframework.retry.interceptor.StatefulRetryOperationsInterceptor.invoke(StatefulRetryOperationsInterceptor.java:132)
      at org.springframework.retry.annotation.AnnotationAwareRetryOperationsInterceptor.invoke(AnnotationAwareRetryOperationsInterceptor.java:118)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
      at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:653)
      at com.acme.push.service.PushService$$EnhancerBySpringCGLIB$$9d503bc1.pushMessage(&lt;generated&gt;)
      at com.acme.push.receiver.PushListener.onMessage(PushListener.java:42)
      at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:799)
      ... 10 more
  </code></pre>
  
  <p>I am pretty sure I am keeping it too simple, but I just have no clues on what could cause this error and how to solve it, anybody has an idea of what is going on ?</p>