aop - AspectJ:切入点中的参数

标签 aop aspectj

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

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

这对于具有至少 2 个参数的方法非常有效:
public void delete(Object item, Session currentSession);

但它不适用于以下方法:
public List listAll(Session currentSession);

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

最佳答案

哦,好吧...我用这个讨厌的技巧解决了这个问题。仍在等待某人以“官方”切入点定义出现。

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);
}

关于aop - AspectJ:切入点中的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/265680/

相关文章:

java - 如何在没有 xml 的 Spring 中运行方面?

java - 当在类和方法中添加带注释的事务时,如何使事务仅在方法中起作用?

java - AspectJ 切入点不适用于外部类和 LTW

java - Spring AOP/AspectJ 记录方法的执行时间,但如何将参数传递给它? ( Spring 启动API)

java - 在运行时更改 guice 实例的值

java - Spring AOP : Passing parameter in aspect method

使用 AspectJ 时发生 Java 字节码错误

java - 与接口(interface)上的注释匹配的 Spring AOP 切入点

java - 建议 spring mvc http 消息转换器

java - 如何在 Spring Roo DBRE 生成的实体中自定义 setter ?