我有一个简单的方面,如下所示:
@Aspect
@Component
public class ApiCallLogAspect {
@AfterReturning(pointcut = "execution(* com.example.web.rest.api.ApiResource.getAddress (String)) && args(mobile))", argNames = "mobile")
public void endpointAfterReturning(String mobile) throws InterruptedException {
Thread.sleep(10000);
System.out.println("This is aspect log.");
}
}
}
这是getAddress
类中的ApiResource
方法,如您所见,这是一种非常简单且快速的方法:
@RestController
@RequestMapping("/api/v1")
public class ApiResource {
public String getAddress(String mobile) {
return "This is your address";
}
}
现在,当我调用getAddress
方法时,Thread.sleep(10000)
方面会延迟执行getAddress
方法。
如何将方面的执行与连接点方法分开?
注意
我用Thread.sleep(10000)
来说明我的问题。我想在方法执行后做一些事情,并且不想影响主方法,无论是延迟,异常还是其他。为此我该怎么做?
更新
我的目标是将请求记录到我的其他api并存储调用详细信息,例如ip,参数值,请求标头和返回值。