日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) >

Spring AOP 和 AspectJ的区别

發(fā)布時(shí)間:2023/12/20 51 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring AOP 和 AspectJ的区别 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

Spring AOP 和 AspectJ的區(qū)別

  • springAOP 是spring支持的面向切面AOP 編程。
  • AspectJ是一個(gè)面向切面的框架,它擴(kuò)展了Java語(yǔ)言。AspectJ定義了AOP語(yǔ)法,它有一個(gè)專門的編譯器用來(lái)生成遵守Java字節(jié)編碼規(guī)范的Class文件。

1. 目標(biāo)不同

springAOP 不是一個(gè)完備的AOP 方案。

AspectJ是最首創(chuàng)的AOP技術(shù),用來(lái)提供全面的AOP方案。

2. 織入方式

  • AspectJ 使用了三種不同類型的織入方式:

Compile-time weaving:編譯期織入。編譯器將切面和應(yīng)用的源代碼編譯在一個(gè)字節(jié)碼文件中。

Post-compile weaving:編譯后織入。也稱為二進(jìn)制織入。將已有的字節(jié)碼文件與切面編制在一起。

Load-time weaving:加載時(shí)織入。與編譯后織入一樣,只是織入時(shí)間會(huì)推遲到類加載到j(luò)vm時(shí)。

  • springAOP使用運(yùn)行時(shí)織入(runtime weaving)

在運(yùn)行時(shí)織入,是使用目標(biāo)對(duì)象的代理對(duì)象織入的。

springAOP的代理模式:

小結(jié):SpringAOP 是基于動(dòng)態(tài)代理的實(shí)現(xiàn)AOP,這意味著實(shí)現(xiàn)目標(biāo)對(duì)象的切面會(huì)創(chuàng)建一個(gè)代理類(如上圖,兩種代理模式)。而AspectJ在程序運(yùn)行期是不會(huì)做任何事情的,因?yàn)轭惡颓忻媸侵苯泳幾g在一起的,這種方式稱為靜態(tài)代理。

3. 連接點(diǎn) Joinpoints

springAOP 只支持方法執(zhí)行連接點(diǎn),而ASpectJ 還支持 方法調(diào)用,構(gòu)造方法調(diào)用,屬性引用,靜態(tài)初始化、其他切面的通知等 作為連接點(diǎn)。 功能相當(dāng)強(qiáng)大。

4.性能

compile-time weaving is much faster than runtime weaving.

編譯期織入要比運(yùn)行期織入快很多。因此aspectJ 的運(yùn)行速度要快于springAOP、

5.總結(jié)

This quick table summarizes the key differences between Spring AOP and AspectJ:

Spring AOPAspectJ
Implemented in pure JavaImplemented using extensions of Java programming language
No need for separate compilation processNeeds AspectJ compiler (ajc) unless LTW is set up
Only runtime weaving is availableRuntime weaving is not available. Supports compile-time, post-compile, and load-time Weaving
Less Powerful – only supports method level weavingMore Powerful – can weave fields, methods, constructors, static initializers, final class/methods, etc…
Can only be implemented on beans managed by Spring containerCan be implemented on all domain objects
Supports only method execution pointcutsSupport all pointcuts
Proxies are created of targeted objects, and aspects are applied on these proxiesAspects are weaved directly into code before application is executed (before runtime)
Much slower than AspectJBetter Performance
Easy to learn and applyComparatively more complicated than Spring AOP

github: https://crossyourheart.github.io/

總結(jié)

以上是生活随笔為你收集整理的Spring AOP 和 AspectJ的区别的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。