Aspectj織入點語法:
1、execution(public * *(..)) 任何類的任何返回值的任何方法
2、execution(* set*(..)) 任何類的set開頭的方法
3、execution(* com.xyz.service.AccountService.*(..)) 任何返回值的規定類裡面的方法
4、execution(* com.xyz.service..*.*(..)) 任何返回值的,規定包或者規定包子包的任何類任何方法
Advise總結。舉例說明:
1、舉例:直接指定要織入的位置和邏輯
[java]
//指定織入的方法。
@Before("execution(public * com.spring.service..*.*(..))")
public void BeforeMethod(){
System.out.println("method start!");
}
@AfterReturning("execution(public * com.spring.service..*.*(..))")
public void AfterMethod(){
System.out.println("After returnning");
}
2、通過定義pointcut來指定:
[java]
//定義pointcut織入點集合
@Pointcut("execution(public * com.spring.service..*.*(..))")
public void MyMethod(){}
@Before("MyMethod()")
public void BeforeMethod(){
System.out.println("method start!");
}
@AfterReturning("MyMethod()")
public void AfterMethod(){
System.out.println("After returnning");
}
//執行前後都攔截。以pjp.proceed的方法分割開來
@Around("MyMethod()")
public void aroundProcced(ProceedingJoinPoint pjp) throws Throwable{
System.out.println("around start");
pjp.proceed();
System.out.println("around end");
}
輸出結果:
method start!
around start
helloworld
After returnning
around end
作者:zhang6622056