**Aspectj織入點語法:**
1、execution(public * *(..))?? 任何類的任何返回值的任何方法
2、execution(* set*(..))?????? 任何類的set開頭的方法
3、execution(* com.xyz.service.AccountService.*(..))??? ?????任何返回值的規定類里面的方法
4、execution(* com.xyz.service..*.*(..))????? 任何返回值的,規定包或者規定包子包的任何類任何方法
**Advise總結。舉例說明:**
1、舉例:直接指定要織入的位置和邏輯
~~~
//指定織入的方法。
@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來指定:
~~~
//定義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
- 前言
- 一、Ioc控制反轉注入原理
- 二、Ioc控制反轉集合注入和Scope
- 三、Bean的懶加載和生命周期
- 四、基于Annotation的bean
- 五、Spring容器組建注解@Component和Resouces實現完全注解配置
- 六、Spring自動裝配注解@Autowired
- 七、Spring Aop的理解和簡單實現
- 八、Spring Aop織入點語法和相關案例總結
- 九、Spring Aop 用xml的方式實現
- 十、Spring DBCP用xml和properties2種格式配置DataSource
- 十一、Spring整合Hibernte
- 十二、Spring中Annotation聲明事務
- 十三、Spring中Xml聲明事務
- 十四、Spring中hibernateTemplate的使用