尝试为任何包含变量的方法匹配AspectJ切入点签名 [英] Trying to match an AspectJ pointcut signature for any methods containing a variable

查看:168
本文介绍了尝试为任何包含变量的方法匹配AspectJ切入点签名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在包含ModelMap的Web控制器中创建一个与 any 方法匹配的切入点:

I want to create a pointcut that matches any method in my Web controller that contains a ModelMap:

pointcut addMenu(ModelMap modelMap) : 
    execution (public String example.web.MyController.*(..)) && args (modelMap);

before(ModelMap modelMap) : addMenu(modelMap) {
    // Do stuff with modelMap...
}

我的问题是,这仅匹配具有 ONLY 的ModelMap参数的方法,而其他不匹配,因为它们包含太多参数.例如,由于有"req"参数,因此未被拦截:

My problem is that this only matches methods with ONLY the ModelMap parameter, others are not matched because they contain too many parameters. For example, this is not intercepted, due to the "req" parameter:

public String request(HttpServletRequest req, ModelMap modelMap) {
    // Handle request
}

是否有任何方法可以将所有方法与ModelMap参数进行匹配,而不必为每种可能的参数组合添加切入点委托?

Is there any way to match all methods with a ModelMap parameter, without having to add a pointcut delegate for every possible parameter combination?

推荐答案

您可以使用通配符*..灵活地表达参数.

You can use wildcards * or .. to express the arguments in a flexible way.

pointcut addMenu(ModelMap modelMap) : 
    execution (public String example.web.MyController.*(..)) && args (*, modelMap);

请参见 AspectJ:切入点中的参数

这篇关于尝试为任何包含变量的方法匹配AspectJ切入点签名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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