I use in my Spring boot project aspect that is fired on every public method in annotated class:
@Aspect
@Component
public class DeletedAwareAspect {
@Before("@within(com.example.DeleteAware)")
public void aroundExecution(JoinPoint pjp) throws Throwable {
//... some logic before
}
@After("@within(com.example.DeleteAware)")
public void cleanUp(JoinPoint pjp) throws Throwable {
//... some logic after
}
}
Usage of that aspect is below:
@DeleteAware
@Service
public class MyService {
public void foo() {}
}
@DeleteAware
@Service
public class MyAnotherService {
@Autowired
private MyService service;
public void anotherFoo() {}
public void VERY_IMPORTANT_METHOD() {
service.foo();
}
}
MyService.foo() and MyAnotherService.anotherFoo() works as expected. But here is the problem - if method wrapped by aspect is called by another aspected method (like VERY_IMPORTANT_METHOD()), I dont want to fire aspect twice, but only once. How to check from Aspect whether method is called inside another aspected method?