Spring AOP中pointcut expression表達(dá)式解析 及匹配多個(gè)條件
任意公共方法的執(zhí)行:
execution(public * (..))
任何一個(gè)以“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.*(..))")
在多個(gè)表達(dá)式之間使用 ||,or表示 或,使用 &&,and表示 與,!表示 非.例如:
@Pointcut("@within(org.springframework.stereotype.Controller) || @within(org.springframework.web.bind.annotation.RestController)")
execution 用于匹配方法執(zhí)行的連接點(diǎn);
@within :使用 “@within(注解類型)” 匹配所以持有指定注解類型內(nèi)的方法;注解類型也必須是全限定類型名;
@annotation :使用 “@annotation(注解類型)” 匹配當(dāng)前執(zhí)行方法持有指定注解的方法;注解類型也必須是全限定類型名;
@args 任何一個(gè)只接受一個(gè)參數(shù)的方法,且方法運(yùn)行時(shí)傳入的參數(shù)持有注解動態(tài)切入點(diǎn),類似于 arg 指示符;
@target 任何目標(biāo)對象持有 Secure 注解的類方法;必須是在目標(biāo)對象上聲明這個(gè)注解,在接口上聲明的對它不起作用
@args :使用 “@args( 注解列表 )” 匹配當(dāng)前執(zhí)行的方法傳入的參數(shù)持有指定注解的執(zhí)行;注解類型也必須是全限定類型名;