Service - 1
@Transactional
public void method1(){
service2.method2();
}
Service - 2
@Transactional
@Retry(Exception.class,3)
public void method2(){
some logic ,may produce an exception
}
Expected: The retry happens three times
Actual: The retry is not happening
Most of the time if there are problems with annotations in Spring, it's because AOP in Spring is based on proxies around the Class. https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#aop-understanding-aop-proxies explains it. So the mechanism for recognizing the calls and exception does not see it when it comes from within the same class.
This should solve the issue:
@Service
public class MyService{
@Autowired
private MyService myService;
public void method1(){
..
myService.method2();
..
}
public void method2(){
..
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.