AspectJ:切入点中的参数 [英] AspectJ: parameter in a pointcut

查看:24
本文介绍了AspectJ:切入点中的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 AspectJ 来建议所有具有所选类的参数的公共方法.我尝试了以下方法:

I'm using AspectJ to advice all the public methods which do have an argument of a chosen class. I tried the following:

pointcut permissionCheckMethods(Session sess) : 
    (execution(public * *(.., Session)) && args(*, sess));

这对于至少有 2 个参数的方法非常有效:

This is working wonderfully for methods with at least 2 arguments:

public void delete(Object item, Session currentSession);

但它不适用于以下方法:

but it does not work with methods like:

public List listAll(Session currentSession);

如何更改切入点以建议两种方法的执行?换句话说:我希望.."通配符代表零个或多个参数",但看起来它的意思是一个或多个"......

How may I change my pointcut to advice both methods executions? In other words: I expected the ".." wildcard to represent "zero or more arguments", but it looks like it means instead "one or more"...

推荐答案

哦……我用这个讨厌的技巧解决了这个问题.仍在等待有人提出官方"切入点定义.

Oh well... I worked that around with this nasty trick. Still waiting for someone to show up with an "official" pointcut definition.

pointcut permissionCheckMethods(EhealthSession eheSess) : 
    (execution(public * *(.., EhealthSession)) && args(*, eheSess))
    && !within(it.___.security.PermissionsCheck);

pointcut permissionCheckMethods2(EhealthSession eheSess) : 
    (execution(public * *(EhealthSession)) && args(eheSess))
    && !within(it.___.security.PermissionsCheck)
    && !within(it.___.app.impl.EhealthApplicationImpl);

before(EhealthSession eheSess) throws AuthorizationException : permissionCheckMethods(eheSess)
{
    Signature sig = thisJoinPointStaticPart.getSignature(); 
    check(eheSess, sig);
}

before(EhealthSession eheSess) throws AuthorizationException : permissionCheckMethods2(eheSess)
{
    Signature sig = thisJoinPointStaticPart.getSignature(); 
    check(eheSess, sig);
}

这篇关于AspectJ:切入点中的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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