工作中遇到了,要针对在原有的切面范围基础之上,排除掉某些类中的方法。所以本篇文章主要介绍了SpringBoot AOP @Pointcut切入点表达式排除某些类中的方法的方式。
示例
@Pointcut("execution(public com.lingyejun.bolg.dto.Result com.lingyejun.blog.web..*Controller.*(..))")
public void normalPointcutWeb() {
}
@Pointcut("execution(public com.lingyejun.bolg.dto.Result com.lingyejun.blog.web.book.controller.SafeBabyController.getBabyBirth(..))")
public void excludePointcutWeb() {
}
@Pointcut("normalPointcutWeb() && !excludePointcutWeb()")
public void allPointcutWeb() {
}
@Before("allPointcutWeb()")
public void startLog(JoinPoint joinPoint) {
String className = joinPoint.getSignature().getDeclaringType().getSimpleName();
String methodName = joinPoint.getSignature().getName();
logger.info("{}.{} start", className, methodName);
}
normalPointcutWeb:切入点为——以public修饰的方法、方法的返回值为com.lingyejun.bolg.dto.Result、类路径为com.lingyejun.blog.web下的所有以Controller结尾的类、携带有任意个参数的切入点。
excludePointcutWeb:切入点为——以public修饰的方法、方法的返回值为com.lingyejun.bolg.dto.Result、类路径为com.lingyejun.blog.web.book.controller.SafeBabyController、方法名为getBabyBirth、携带任意个参数的切入点。
allPointcutWeb:切入点为满足normalPointcutWeb且不满足excludePointcutWeb的切入点的范围