如何从 Spring 控制器获取 AOP 建议中的 RequestMapping 请求? [英] How do you get RequestMapping request in AOP advice from a Spring controller?

查看:58
本文介绍了如何从 Spring 控制器获取 AOP 建议中的 RequestMapping 请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给定某种带有请求映射的控制器

Given some kind of controller with a request mapping

@RequestMapping(value="/some/path", method=RequestMethod.POST)

您将如何检索方面类中的方法值 (RequestMethod.POST)?

How would you retrieve the method value (RequestMethod.POST) in the aspect class?

我想跟踪所有执行 POST 请求的控制器方法.

I want to keep track of all the controller methods that perform a POST request.

谢谢

推荐答案

找到了解决方案.

import org.aspectj.lang.reflect.MethodSignature;
import java.lang.reflect.Method;

@Pointcut("within(@org.springframework.stereotype.Controller *)")
public void controller() {}

// In advice
MethodSignature methodSignature = (MethodSignature) joinPoint.getSignature();
Method method = methodSignature .getMethod();
RequestMethod[] requestMethods = method.getAnnotation(RequestMapping.class).method();

注意你导入的类.

这篇关于如何从 Spring 控制器获取 AOP 建议中的 RequestMapping 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆