AOP 总结
AOP即Aspect oriented Programing, 面向切面編程。
相關術語:
通知(Advice):
Advice defineds when to execute what action.
通知定義了切面要執行的內容以及在什么時候執行該內容。
Spring支持的5種通知類型:
- Before - org.springframework.aop.MethodBeforeAdvice
- After-returning - org.springframework.aop.AfterRetruningAdvice
- After-throwing - org.springframework.aop.ThrowsAdvice
- Arount - org.aopaliance.intercept.MethodInterceptor
- Introduction - org.springframework.aop.IntroductionInterceptor
連接點(JoinPoint):
The time to execute advice.
連接點指明了應用通知的時機,比如方法執行時,異常拋出時等。
切入點(PointCut):
Where to execute the action.
定義了在什么地方去執行織入的操作, 比如某個類名或者方法名。可以使用正則表達式表示。
切面(Aspect):
The advice and pointcut makes up the aspect to specify where and when to execute the action.
通知和切入點共同組成了切面,即為動作要執行的時間,內容和地點。
引入(Introduction):
Allows us to add new methods or properties to a class.
引入允許向現有的類添加新的方法和屬性(Spring引入類方法注入的功能)
目標(Target):
The target got adviced. If there's no AOP, the target need to execute other kind of logics like recording log, transaction controlle, and with AOP, it can focus on its own business logic.
被通知的對象。不使用AOP的時候,目標的邏輯需要交叉其它的諸如日志記錄,事務控制等事務邏輯,使用AOP的時候,則只需要關注自己的業務邏輯就可以了。
代理(Proxy):
The object to apply advice.
應用通知的對象。
織入(Weaving):
Apply the aspect to the target to generate the proxy.
把切面應用到目標對象來創建代理對象的過程,織入一般發生在如下幾個時機:
- 編譯時: 當一個類文件被編譯時織入,需要特殊的編譯器才能實現,比如AspectJ的編譯器
- 類加載時: 當使用特殊的類加載器在目標被加載到虛擬機之前增強類的字節代碼
- 運行時: 切面在運行的某個時刻被織入,SpringAOP就是以此種方式織入的,原理是是用了JDK的動態代理技術。
實現方式
轉載于:https://www.cnblogs.com/developerERA/p/7084482.html
總結
- 上一篇: C++ Primer 第9章 顺序容器
- 下一篇: 使用Filter跟踪Asp.net MV