在springAOP里面获取request和response对象

@Component
@Aspect
public class WebControllerAop {
    @Pointcut("execution(* cn.sky.controller.*..*.*(..))")
    public void executeService() {
    }
    @Around(value="executeService()")//好的
//  @Around(value="executeService()&&(args(request,..) || args(..,request))")//好的
//  @Around(value="executeService()&&(args(..,request,response)||args(request,response,..))")//好的
    public Object doAroundAdvice(ProceedingJoinPoint proceedingJoinPoint) throws Exception {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse();
        Signature signature = proceedingJoinPoint.getSignature();
        MethodSignature methodSignature = (MethodSignature)signature;    
        Method targetMethod = methodSignature.getMethod();
        Method realMethod = proceedingJoinPoint.getTarget().getClass().getDeclaredMethod(signature.getName(), targetMethod.getParameterTypes()); 
        Object obj = proceedingJoinPoint.proceed();
        return obj;
    }
}

你可能感兴趣的:(java)