Question

I have service that has several overloaded methods, for example:

MyService.execute(Long id); 
MyService.execute(Collection collection);

And i need to intercept only execution of 'MyService.execute(Long id)' via AOP like:

@Aspect 
@Component
public class AopInterseptor{

  @After("execution(* my.Service.MyService.execute(..))") 
  public void intercept(JoinPoint joinPoint) throws Exception { 
    // Do stuff 
  } 
}

Is it possible to do so?

Was it helpful?

Solution

What about:

@Aspect 
@Component 
public class AopInterseptor{

  @After("execution(* my.Service.MyService.execute(Long))") 
  public void intercept(JoinPoint joinPoint) throws Exception 
  {  
    // Do stuff 
  }

}

This Poincut designator matches only if there is only one param with type Long given in the method call.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top