Spring AOP中pointcut expression表達式解析 及匹配多個條件
任意公共方法的執(zhí)行:
execution(public * (..))
任何一個以“set”開始的方法的執(zhí)行:
execution( set(..))
AccountService 接口的任意方法的執(zhí)行:
execution( com.xyz.service.AccountService.(..))
定義在service包里的任意方法的執(zhí)行:
execution( com.xyz.service..(..))
定義在service包和所有子包里的任意類的任意方法的執(zhí)行:
execution(* com.xyz.service...(..))
定義在pointcutexp包和所有子包里的JoinPointObjP2類的任意方法的執(zhí)行:
execution(* com.test.spring.aop.pointcutexp..JoinPointObjP2.*(..))")
在多個表達式之間使用 ||,or表示 或,使用 &&,and表示 與,!表示 非.例如:
@Pointcut("@within(org.springframework.stereotype.Controller) || @within(org.springframework.web.bind.annotation.RestController)")
execution 用于匹配方法執(zhí)行的連接點;
@within :使用 “@within(注解類型)” 匹配所以持有指定注解類型內的方法;注解類型也必須是全限定類型名;
@annotation :使用 “@annotation(注解類型)” 匹配當前執(zhí)行方法持有指定注解的方法;注解類型也必須是全限定類型名;
@args 任何一個只接受一個參數(shù)的方法,且方法運行時傳入的參數(shù)持有注解動態(tài)切入點,類似于 arg 指示符;
@target 任何目標對象持有 Secure 注解的類方法;必須是在目標對象上聲明這個注解,在接口上聲明的對它不起作用
@args :使用 “@args( 注解列表 )” 匹配當前執(zhí)行的方法傳入的參數(shù)持有指定注解的執(zhí)行;注解類型也必須是全限定類型名;