我的服务有多个重载方法,例如:
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
}
}
是否可以这样做?
答案 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指示符才会匹配。