0

I have a spring component with a method I need to check:

String methodA(String param) {
...//do something 
}

Now I create an aspect to catch method execution:

@Aspect
@Component
@ConditionalOnProperty(name = "is.enabled", matchIfMissing = true)
public class LoggingAspect {
     
@AfterReturning(pointcut = "execution(* com.A.methodA(..))", returning = "result")
void logMethodA(String result) {
    ...//do something with result
}

In properties flag is set to true to trigger aspect

is.enabled=true

also tried execution(* com.A.methodA(String)) and no changes. Copied methods from working aspects, they get triggered, can't find the clue.

user2508615
  • 213
  • 2
  • 16
  • Check the following . 1. Is `methodA` triggered through an internal method call ? If yes , internal method calls cannot be adviced . 2. Is `LogginAspect` initialized as a bean . A complete reproducible code shared will help you find answers easily. – R.G Jul 27 '21 at 08:37
  • Yep, methodA is not called outside of class, just via other method, so its not possible to aspect it ? – user2508615 Jul 27 '21 at 10:30
  • Please go through my answer for a similar question [here](https://stackoverflow.com/a/68194594/4214241) – R.G Jul 27 '21 at 10:31
  • This is a Spring AOP limitation and native AspectJ offers much more . Please read through this [Q&A](https://stackoverflow.com/questions/56614354/why-does-self-invocation-not-work-for-spring-proxies-e-g-with-aop) as well. – R.G Jul 27 '21 at 10:39

1 Answers1

0

You should check if your LoggingAspect is registered as a bean in the Spring context at all. Try to remove or change @ConditionalOnProperty to @ConditionalOnProperty(value = "is.enabled", havingValue = true, matchIfMissing = true).

Andrey
  • 433
  • 1
  • 5
  • 19