项目类型 | 描述 |
---|---|
arg() | 限定连接点方法参数 |
@args() | 通过连接点方法参数上的注解进行限定 |
execution() | 用于匹配是连接点的执行方法 |
this() | 限制连接点匹配AOP代理Bean引用为指定的类型 |
target | 目标对象(即被代理对象) |
@target() | 限制目标对象的配置了指定的注解 |
within | 限制连接点匹配执行的类型 |
@windin() | 限定连接点带有匹配注解类型 |
@annotation | 限定带有指定注解的连接点 |
Poincut()
1.execution()举例
@Pointcut("execution(* com.sample.common.model.a..*.*(..))")
public void pointCut(){
}
@Before("pointCut()")
public void before(){
}
@After("pointCut()")
public void after(){
}
2.@annotation举例
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.METHOD, ElementType.TYPE})
@Documented
public @interface testAnnotation {
String module() default "单元内容";
String action() default "查询方法";
}
@Pointcut("@annotation(com.sample.common.test.annotation.testAnnotation)")
public void pointCut(){
}
@AfterThrowing(throwing ="ex",pointcut="pointCut()")
public void afterThrowing(JoinPoint joinPoint,Throwable ex){
}
@AfterReturning(returning="rvt", pointcut="pointCut()")
public Object AfterExec(JoinPoint joinPoint,Object rvt) {
}
PS:Spring提供了一个注解@Order 可以在多个切片时,调整切片顺序,@Before 是从小到大运行,@After 是从大到小运行