close
 (此圖來源Spring官網改之)


說明:
Spring AOP (Aspect-Oriented Programming)

如果沒用過AOP的人來說,這有許多抽象術語名詞,
真的難以理解,
如果用Aspect-Oriented Programming字面解釋
Aspect: 多方面,外觀,方面,方向
Oriented: 導向的,導向
Programming : 編程,程式設計

AOP中文名稱: 多方面導向程式設計
也有稱為:面向導向設計…等很多種中文名稱。

不管中文是什麼,記好AOP 就好了。

不廢話了。

本文主要列出 AOP 的功能


一、Advices:
目前 Spring AOP 有4種 Advices
Before Advices – 指定物件的方法執行之前被呼叫
After Returning Advices – 指定物件的方法執行結果後被呼叫
After Throwing Advices – 指定物件的方法執行中發生錯誤例外被呼叫
Around Advices – 指定物件的方法包含以上三項


二、Pointcut、Advisor:
Pointcut - 指定物件的方法的名字或使用正則表示式,來攔截方法處理程序。
Advisor - 用Advice和Pointcut組成一個程式,來攔截方法處理程序。
常用:NameMatchMethodPointcutAdvisor 、 RegExpMethodPointcutAdvisor

三、Introduction:
將原有己寫好的物件方法,在不用修改該物件程式,可以附加上新的方法處理程序。

四、Autoproxing:
原在設定各種攔截,需一個一個設定那個方法要攔截。使用Autoproxing為自動代理。
如設定 *Service 就是 方法名稱 最後有Service的方法。
例:TestService、 xxxxxService 等,都會被攔截。


程式範例:
一、Advices:
Spring Hello World Example 專案 之 AOP Before


二、Pointcut、Advisor:
待續…

三、Introduction:
待續…

四、Autoproxing:
待續…




















其它文章

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

arrow
arrow

    PG Levin Li 發表在 痞客邦 留言(0) 人氣()