2016-07-05 41 views
4

次のコードは再試行しません。私は何が欠けていますか?Springboot @retryableが再試行しない

@EnableRetry 
@SpringBootApplication 
public class App implements CommandLineRunner 
{ 
    ......... 
    ......... 


    @Retryable() 
    ResponseEntity<String> authenticate(RestTemplate restTemplate, HttpEntity<MultiValueMap<String, String>> entity) throws Exception 
    { 
     System.out.println("try!"); 
     throw new Exception(); 
     //return restTemplate.exchange(auth_endpoint, HttpMethod.POST, entity, String.class); 
    } 

私は以下をpom.xmlに追加しました。

<dependency> 
     <groupId>org.springframework.retry</groupId> 
     <artifactId>spring-retry</artifactId> 
     <version>1.1.2.RELEASE</version> 
    </dependency> 
    <dependency> 
     <groupId>org.springframework.boot</groupId> 
     <artifactId>spring-boot-starter-aop</artifactId> 
    </dependency> 

@Retryableにさまざまな引数の組み合わせを指定してみました。

@Retryable(maxAttempts=10,value=Exception.class,[email protected](delay = 2000,multiplier=2)) 

ありがとうございます。

+0

私は同じ問題に直面しています。 –

答えて

2

発見されるメソッドの注釈については、初期化コンテキストから正しく呼び出す必要があります。このメソッドは、SpringコンテキストからのBeanから呼び出されるか、または他の手段によって呼び出されますか?

これをテストする場合は、SpringJunit4ClassRunnerを使用しているランナーですか?

+0

ありがとう、私はこれを見るチャンスがない、私は戻ってくるだろう。 – engg

+0

@enggは機能しましたか? – UserF40

+0

申し訳ありませんが、私はまだチェックしていない、更新し、更新します。 – engg

6

私はそれを解決しました。再試行しようとしているメソッドから何かを返すと、@ Retryable()が動作していないことが分かりました。 service.javaで

のpom.xmlでのMavenの依存関係

<dependency> 
     <groupId>org.springframework.retry</groupId> 
     <artifactId>spring-retry</artifactId> 
     <version>1.1.5.RELEASE</version> 
    </dependency> 

春ブーツApplication.java

@SpringBootApplication 
@EnableTransactionManagement 
@EnableRetry 
public class Application { 

    public static void main(String[] args) throws Exception { 
     SpringApplication.run(Application.class, args); 
    } 

} 
controller.javaで

@RestController 
public class JavaAllDataTypeController { 

@Autowired 
JavaAllDataTypeService JavaAllDataTypeService; 


@RequestMapping(
     value = "/springReTryTest", 
     method = RequestMethod.GET 
) 
public ResponseEntity<String> springReTryTest() { 

    System.out.println("springReTryTest controller"); 

    try { 
     JavaAllDataTypeService.springReTryTest(); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

    return new ResponseEntity<String>("abcd", HttpStatus.OK); 
    } 

} 

@Service 
@Transactional 
public class JavaAllDataTypeService { 

// try the method 9 times with 2 seconds delay. 
@Retryable(maxAttempts=9,value=Exception.class,[email protected](delay = 2000)) 
public void springReTryTest() throws Exception { 

    System.out.println("try!"); 
    throw new Exception(); 
    } 

} 

出力:例外をスローして9回試行しています。

enter image description here

+0

まだ戻り値の型を削除しても機能しない:( –

関連する問題