【问题标题】:Using AspectJ to intercept method call and bind it to another method使用 AspectJ 拦截方法调用并将其绑定到另一个方法
【发布时间】:2017-04-18 20:30:57
【问题描述】:

我是 AOP 的新手,已经阅读了这里的教程:https://eclipse.org/aspectj/,并且对方面的工作原理有了基本的了解。

这就是我想要做的。

有一个名为“MyAnnotation”的@annotation,假设我有一个这样装饰的方法

@MyAnnotation
public void MyMethod() {
    //something here
}

我写了一个像这样的切面类:

@Aspect
public class MyAspect { 

@Around("@annotation(MyAnnotation)")
public void MyAdvice(ProceedingJoinPoint p) throws Throwable {
    // I want to call an intereceptor here, for example
    SomeInterceptor.invoke(methodInvocation)
    p.proceed();
}
}

SomeInterceptor 在依赖包中,我不拥有代码。它扩展了org.aopalliance.intercept 中的MethodInterceptor 类。在调用MyMethod 之前,它会在我的建议方法中进行一些处理。我不能使用 Guice.bindInterceptor 并且正在寻找类似的替代方案。我不确定如何获取可以传递给调用方法的methodInvocation 对象。

谢谢!

【问题讨论】:

    标签: aop aspectj spring-aop interceptor


    【解决方案1】:

    这正是我需要的:https://github.com/eclipse/org.aspectj/tree/master/docs/sandbox/aopalliance

    这是 aspectJ 和 AOPAlliance 之间的桥梁。

    【讨论】:

      猜你喜欢
      • 2012-08-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-11
      • 2021-09-16
      • 1970-01-01
      相关资源
      最近更新 更多