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

查看:1983
本文介绍了如何从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天全站免登陆