I'm trying to intercept a method test()
using annotation @Myfinder
and return value Result
.
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Myfinder {}
@Aspect
@Component
public class MyAspect {
@AfterReturning(value="@annotation(com.<MypackageHide>.MyFinder)",returning="result")
public void after(JoinPoint joinPoint, Result result) {
//something
}
But it is intercepted only if I call it through rest api /test
. I want to intercept even if this method is called from repair()
method.
@RequestMapping(path = "/repair")
@RestController
@Configurable
public class MyController {
@PostMapping("")
public ResponseEntity<String> repair() {
//some code
test(); // <=============== not intercepted if i call /repair
return ResponseEntity.ok("dummy");
}
@MyFinder
@PostMapping("/test") // <===== intercepted if i call this independently
public Result test() {
System.out.println("^^^^^^^");
return (Result) null;
}
}
I want this to be called even if I call /repair
I'm fairly new to AOP