【发布时间】:2013-07-22 13:25:13
【问题描述】:
如何编写一个 Spring @AspectJ 切入点 (@Pointcut) 表达式来匹配一个类中的所有公共方法,而不考虑它们的参数列表?
我想要一个具有@AfterThrowing 切入点的切面所有具有特定注释的特定类的公共方法@MyAnnotation(类似于其他人在@987654321 中想要的@)。目前我的方面是这样的:
@Aspect
public final class ServiceDataAccessExceptionReporter {
@Pointcut("execution(public * com.example.Service.*(..)) && @annotation(com.example.MyAnnotation))")
public void annotatedMethod() {}
@AfterThrowing(pointcut = "annotatedMethod()", throwing = "exception")
public void reportException(final DataAccessException exception) {
...
}
}
Eclipse Spring 插件 表明(使用源代码窗口中的箭头注释)这是正确地建议方法com.example.Service.getNames()。但这并不表示已经建议有参数的方法,例如com.example.Service.getTimes(String name)。
那是因为带有@Pointcut 注解的方法没有参数吗?我怎样才能使切入点成为所有方法,而不管它们的参数列表如何?或者我必须为我的com.example.Service 类中的每种参数列表设置一个单独的@Pointcut?
【问题讨论】:
标签: eclipse spring aop aspectj pointcut