javascript
Spring AOP 和 AspectJ的区别
Spring AOP 和 AspectJ的區別
- springAOP 是spring支持的面向切面AOP 編程。
- AspectJ是一個面向切面的框架,它擴展了Java語言。AspectJ定義了AOP語法,它有一個專門的編譯器用來生成遵守Java字節編碼規范的Class文件。
1. 目標不同
springAOP 不是一個完備的AOP 方案。
AspectJ是最首創的AOP技術,用來提供全面的AOP方案。
2. 織入方式
- AspectJ 使用了三種不同類型的織入方式:
Compile-time weaving:編譯期織入。編譯器將切面和應用的源代碼編譯在一個字節碼文件中。
Post-compile weaving:編譯后織入。也稱為二進制織入。將已有的字節碼文件與切面編制在一起。
Load-time weaving:加載時織入。與編譯后織入一樣,只是織入時間會推遲到類加載到jvm時。
- springAOP使用運行時織入(runtime weaving)
在運行時織入,是使用目標對象的代理對象織入的。
springAOP的代理模式:
小結:SpringAOP 是基于動態代理的實現AOP,這意味著實現目標對象的切面會創建一個代理類(如上圖,兩種代理模式)。而AspectJ在程序運行期是不會做任何事情的,因為類和切面是直接編譯在一起的,這種方式稱為靜態代理。
3. 連接點 Joinpoints
springAOP 只支持方法執行連接點,而ASpectJ 還支持 方法調用,構造方法調用,屬性引用,靜態初始化、其他切面的通知等 作為連接點。 功能相當強大。
4.性能
compile-time weaving is much faster than runtime weaving.
編譯期織入要比運行期織入快很多。因此aspectJ 的運行速度要快于springAOP、
5.總結
This quick table summarizes the key differences between Spring AOP and AspectJ:
| Implemented in pure Java | Implemented using extensions of Java programming language |
| No need for separate compilation process | Needs AspectJ compiler (ajc) unless LTW is set up |
| Only runtime weaving is available | Runtime weaving is not available. Supports compile-time, post-compile, and load-time Weaving |
| Less Powerful – only supports method level weaving | More Powerful – can weave fields, methods, constructors, static initializers, final class/methods, etc… |
| Can only be implemented on beans managed by Spring container | Can be implemented on all domain objects |
| Supports only method execution pointcuts | Support all pointcuts |
| Proxies are created of targeted objects, and aspects are applied on these proxies | Aspects are weaved directly into code before application is executed (before runtime) |
| Much slower than AspectJ | Better Performance |
| Easy to learn and apply | Comparatively more complicated than Spring AOP |
github: https://crossyourheart.github.io/
總結
以上是生活随笔為你收集整理的Spring AOP 和 AspectJ的区别的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java中实例化对象是什么意思
- 下一篇: linux子系统下载错误,Win10系统