基于Spring Annotation的AOP拦截在父类中实现的方法 [英] Spring Annotation based AOP to intercept method implemented in parent class

查看:1106
本文介绍了基于Spring Annotation的AOP拦截在父类中实现的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们将基于注释的AOP用于拦截功能的方法.

We are using annotation based AOP for methods to intercept functionality.

基本界面:

public interface BaseInterface { 
    public void someMethod();
}

抽象基础实现:

public abstract class AbstractBaseImplementation implements BaseInterface {
    public void someMethod() {
       //some logic
    }
}

子界面:

public interface ChildInterface extends BaseInterface {
  public void anotherMethod();
}

实施班

public class ActualImplemetation extends AbstractBaseImplementation implements ChildInterface {

   public void anotherMethod() {
     // Some logic
   }
}

AbstractBaseImplementation扩展了许多类.创建自定义注释"以标识切入点.

There are many classes extended from the AbstractBaseImplementation. Custom Annotation is created for identifying the point cuts.

方面是

@Aspect
public class SomeAspect {

  @Before("@annotation(customAnnotation)")
  public void someMethod(JoinPoint joinPoint) {
     //Intercept logic
  }

}

我们如何使用基于注释的AOP拦截ActualImplemetation.someMethod(在父类中实现)?

How can we intercept ActualImplemetation.someMethod (Which is implemented in the parent class) using Annotation based AOP?

使用aop配置,可以通过

Using aop configuration this can be achieved by

<aop:advisor pointcut="execution(* com.package..*ActualImplemetation .someMethod(..))" advice-ref="someInterceptor" />

推荐答案

类似的东西:

@Pointcut("execution(* com.package.*ActualImplemetation.someMethod(..))"
// OR
// using BaseInterface reference directly, you can use all sub-interface/sub-class methods
//@Pointcut("execution(* com.package.BaseInterface.someMethod(..))"
logMethod() { //ignore method syntax
 //.....
}

这篇关于基于Spring Annotation的AOP拦截在父类中实现的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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