[英]Spring boot @Cacheable not working as expected with @Transactional
[英]Spring Boot Retry Not Working As Expected when using with Transactional
服務 - 1
@Transactional
public void method1(){
service2.method2();
}
服務 - 2
@Transactional
@Retry(Exception.class,3)
public void method2(){
some logic ,may produce an exception
}
預期:重試發生 3 次
實際:重試未發生
大多數情況下,如果 Spring 中的注釋存在問題,那是因為 Spring 中的 AOP 是基於 Class 周圍的代理。 https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#aop-understanding-aop-proxies解釋了它。 因此,當它來自同一個 class 時,識別調用和異常的機制不會看到它。
這應該可以解決問題:
@Service
public class MyService{
@Autowired
private MyService myService;
public void method1(){
..
myService.method2();
..
}
public void method2(){
..
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.