通过AOP拦截重载方法

时间:2014-04-08 11:46:24

标签: java spring aspectj spring-aop

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

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

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

@Aspect 
@Component
public class AopInterseptor{

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

是否可以这样做?

1 个答案:

答案 0 :(得分:5)

怎么样:

@Aspect 
@Component 
public class AopInterseptor{

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

}

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