execution
within
this
target
args
@target
@within
@agrs
@annotation
&&
||
!java
execution(modifiers-pattern? ret-type-pattern declaring-type-pattern?name-pattern(param-pattern) throws-pattern?)
?表明能夠不存在spring
execution(public * *(..)) 任意方法 execution(* set*(..)) 任意以set開頭的方法 execution(* com.xyz.service.AccountService.*(..)) AccountService類下的任意方法 execution(* com.xyz.service.*.*(..)) service包下的任意方法,不包含子包 execution(* com.xyz.service..*.*(..)) service包下的任意方法,包含子包 execution(* com.xyz.service.*.*()) service包下不帶參數的方法 execution(* com.xyz.service.*.*(*,String)) service包下帶兩參數的方法
匹配類型app
within(com.xyz.service.*) service包下的任意方法 within(com.xyz.service..*) service包及子包下的任意方法 this(com.xyz.service.AccountService) AccountService類下的任意方法
this,target與within相似,this
args(java.io.Serializable)
@target,@within差很少,都是類上有某個註解,就匹配任意方法
@within特指當前類的的方法,不包含父類未重寫的或未重載的方法 @target包含父類的方法.net
@within(org.springframework.transaction.annotation.Transactional) @target(org.springframework.transaction.annotation.Transactional)
方法上存在某個註解pwa
方法參數上存在某個註解code
若是要帶參數xml
@AfterReturning( pointcut="com.xyz.myapp.SystemArchitecture.dataAccessOperation()", returning="retVal") public void doAccessCheck(Object retVal) { // ... }
@AfterThrowing( pointcut="com.xyz.myapp.SystemArchitecture.dataAccessOperation()", throwing="ex") public void doRecoveryActions(DataAccessException ex) { // ... }
@Around("com.xyz.myapp.SystemArchitecture.businessService()") public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable { // start stopwatch Object retVal = pjp.proceed(); // stop stopwatch return retVal; }
@Befor 若是要帶參數get
@Pointcut("com.xyz.myapp.SystemArchitecture.dataAccessOperation() && args(account,..)") private void accountDataAccessOperation(Account account) {} @Before("accountDataAccessOperation(account)") public void validateAccount(Account account) { // ... }
@Before("com.xyz.lib.Pointcuts.anyPublicMethod() && @annotation(auditable)") public void audit(Auditable auditable) { AuditCode code = auditable.value(); // ... }
@Before(value="com.xyz.lib.Pointcuts.anyPublicMethod() && target(bean) && @annotation(auditable)", argNames="bean,auditable") public void audit(JoinPoint jp, Object bean, Auditable auditable) { AuditCode code = auditable.value(); // ... use code, bean, and jp }