说明:
本文以环绕切面配合反射、注解为示例
@Around(value = "cutMethods() && withAnnotationMethods()")
public Object around(ProceedingJoinPoint point) throws Throwable {
long startTime = System.currentTimeMillis();
//通过请求上下文持有者,获取 Servlet 容器对象
ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
//通过 Servlet 容器对象获取 request 请求对象
HttpServletRequest request = attributes.getRequest();
MethodSignature methodSignature = (MethodSignature) point.getSignature();
Method method = methodSignature.getMethod();
BusinessLock lockAnnotation = method.getAnnotation(BusinessLock.class);
//获取所有