2017-12-16 7 views
0

spring-retryにリスナーを登録するには@Retryable()注釈?聴覚を春の@登録可能に登録する方法

@Bean 
public RetryListener myRetryListener() { 
    return new MyRetryListener(); 
} 

@Service 
public class SampleService { 
    private int cnt = 1; 

    @Retryable(RuntimeException.class) 
    public void retryMethod(int x) throws Exception { 
     System.out.println("SampleService invoked."); 
     Thread.sleep(500); 

     if (cnt++ < 4) { 
     throw new RuntimeException("SampleService throwing exception"); 
     } 
    } 

} 

私は任意のリスナーBeanを作成した場合、それは自動的にRetryTemplateに登録されます。だから私は複数のリスナーを持っている場合、私は再試行可能なサービスを聞くように特定のリスナーに尋ねることができますか?

答えて

関連する問題