0

I am using a custom annotation and created around aspect for it. Aspect method is getting executed if it is on the service method called from controller. But if I place it on a intermediate method in service class, around aspect method is not getting executed.

Below is the code,

TestServiceImpl.java

@Override
@TestAround
public ResponseDto testMethod(String param1) {
   testMethod2(param1);
   ...
}

public void testMethod2(String param1) {   
  ...
} 

TestAround.java
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface TestAround {    
 ...
}

TestChangeAspect.java
@Around("@annotation(com.annotation.TestAround")
public Object testChangeAspectMethod(ProceedingJoinPoint joinPoint) throws Throwable {
.....
}

Above code works good and testChangeAspectMethod method is getting executed when testMethod from service class is called from Controller.

But if I have modify like below, moving the annotation to testMethod2, aspect method is not getting executed.

@Override    
public ResponseDto testMethod(String param1) {
   testMethod2(param1);
   ...
}

@TestAround
public void testMethod2(String param1) {   
  ...
} 

Why is the aspect method not getting executed when I change like above?

halfer
  • 19,824
  • 17
  • 99
  • 186
Lolly
  • 34,250
  • 42
  • 115
  • 150

0 Answers0