I am using spring aop to create an annotation for some crosscut purpose. Below is the sample:
@Aspect
@Component
@Slf4j
public class MyAspect {
@Before("@annotation(MyAnnotationCheck)")
@SneakyThrows
public void check(JoinPoint joinPoint) {
......
}
}
However, when I use the annotation at the method methodB that was called by another methodA as below, the aspect is not triggered. Note methodA and methodB are both in same service class OperationService.java. This class will be autowired and used in other class (like a controller).
public void methodA(MyRequest request) {
.......
methodB(request);
}
@MyAnnotationCheck(checkType = "abc")
public void methodB(MyRequest request) {
EntityA objA = myService.loadFromDB(); // Reload the object from DB
}
If I test with directly put the annotation on the methodA? It seems working fine. Is it expected? Why?