在 Spring 中,我们可以共享常见的切入点定义,如下所示
@Aspect
public class SystemArchitecture {
/**
* A join point is in the web layer if the method is defined
* in a type in the com.xyz.someapp.web package or any sub-package
* under that.
*/
@Pointcut("within(com.xyz.someapp.web..*)")
public void inWebLayer() {}
}
以上可以像下面一样使用
@Aspect
public class MyAspect {
@AfterThrowing(pointcut = "inWebLayer() ")
public void processError(JoinPoint jp) {
logger.info("Enter:processError");
}
}
是否可以将关节点传递给共享点切割定义。
如下所示,myCustomCheck 是另一个共享切入点定义,它根据传递给它的关节点检查某些内容。
@Aspect
public class MyAspect {
@AfterThrowing(pointcut = "inWebLayer() && myCustomCheck(jp) ")
public void processError(JoinPoint jp) {
logger.info("Enter:processError");
}
}
这可行吗?
谢谢
生活。