通过AOP拦截重载方法

sta*_*kov 2 java spring aspectj spring-aop

我有几个重载方法的服务,例如:

MyService.execute(Long id); 
MyService.execute(Collection collection);
Run Code Online (Sandbox Code Playgroud)

我需要通过AOP拦截'MyService.execute(Long id)'的执行,如:

@Aspect 
@Component
public class AopInterseptor{

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

有可能这样做吗?

mar*_*usw 5

关于什么:

@Aspect 
@Component 
public class AopInterseptor{

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

}
Run Code Online (Sandbox Code Playgroud)

只有在方法调用中只有一个类型为Long的参数时,此Poincut指示符才匹配.