I am trying to use @AfterReturning of AspectJ to get return value of a specific function call.
Not sure why @AfterReturning not working for the following method call.
Though I am trying to use @AfterReturning on 2 methods of same class, 1 works when another didn't. Only difference between two methods are number of arguments, where @AfterReturning working for method with one argument.
Working
@AfterReturning(
pointcut = "execution(org.springframework.http.ResponseEntity com.service.QueryGenerationService.method1(*))",
returning = "retVal"
)
public void interceptMethod1(ResponseEntity retVal) {
System.out.println(retVal+"---->");
}
Not working
@AfterReturning(
pointcut = "execution(com.entity.ReportGenerationExportResult com.service.QueryGenerationService.method2(com.entity.ReportGenerationServiceRequest, com.entity.querybuilder.QueryBuilderResponse))",
returning = "retVal"
)
public void interceptMethod2(ReportGenerationExportResult retVal) {
System.out.println(retVal);
}
Generic specification also not working(for 2 method parameters)
@AfterReturning(
pointcut = "execution(* com.service.QueryGenerationService.method2(*, *))",
returning = "retVal"
)
public void test1(Object retVal){
System.out.println(retVal);
}
Service class where 2 methods exist
@Service
public class QueryGenerationService {
public ResponseEntity method1(
ReportGenerationServiceRequest request
) throws Exception
{
//some logic
ReportGenerationExportResult exportResult = method2(request, queryBuilderResponse);
return toResponseEntity(exportResult);
}
public ReportGenerationExportResult method2(
ReportGenerationServiceRequest originalRequest,
QueryBuilderResponse queryBuilderResponse
) throws Exception
{
//some logic
return reportGenerationExportResult;
}
}
How can I successfully get the return value of second method?