0
votes

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

Base interface:

public interface BaseInterface { 
    public void someMethod();
}

Abstract Base implementation:

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

Child interface:

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

Implementation Class

public class ActualImplemetation extends AbstractBaseImplementation implements ChildInterface {

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

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

Aspect is

@Aspect
public class SomeAspect {

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

}

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

Using aop configuration this can be achieved by

<aop:advisor pointcut="execution(* com.package..*ActualImplemetation .someMethod(..))" advice-ref="someInterceptor" />
2
Did you read the documents? It's all described there with examples. - Abhinav Sarkar

2 Answers

1
votes

Something like :

@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
 //.....
}
1
votes

This should work with some modification:

@Pointcut("execution(@CustomAnnotation * *(..))")
public void customAnnotationAnnotatedMethods() {/**/}   


@Before("customAnnotationAnnotatedMethods()")
public void adviceBeforeCustomAnnotation() {
    ...
}