Aop終極奧義

2021-09-24 13:47:37 字數 1925 閱讀 2683

一:aop也能實現過濾攔截操作,那麼 aop和***、過濾器之間的區別:

1.過濾器是作用於url,***也是作用於url,不同的是過濾器攔截所有的請求,而***僅僅攔截方法,aop是作用於所有方法(包括controller以及service)也就是說aop的攔截作用範圍小,但是他的細緻程度是最高的,不像過濾器***僅僅針對乙個url進行攔截,沒有特定的條件

2.三者執行順序為:過濾器、***、aop,越是接近**才處理邏輯就越是耗費資源,因此有必要並且可以的話,優先順序按照順序來,如果要做細粒度的,比如事務或者是日誌攔截這種需要進行細緻處理的操作,只能用aop來進行特定執行。

3.aop 的@before 、@after、@around方法:

@around是環繞在方法前後(入棧和出棧之間),因為會有個  pjp.proceed(); 方法,此方法代表真正執行了方法,因此可以在之間進行一些事物以及列印日誌的需求。具體使用:

方式一:

@around(value="execution(* *..service.*(..)) && @annotation(transaction)")

public object around(proceedingjoinpoint pjp, transaction transaction) throws throwable

方式二:

@pointcut("execution(public * com.bestpay.bigdata.aiplus..*controller.*(..)))")

private void requestcut()

threadlocalstarttime = new threadlocal<>();

@before("requestcut()")

public void dobefore(joinpoint joinpoint) throws throwable {

@around("requestcut()")

public object doaround(proceedingjoinpoint joinpoint) throws throwable {方法三:@pointcut("@annotation(com.hmily.tcc.annotation.tcc)")

切點作用於含有註解的類或者方法上

二:aop各種方法例項:

proceedingjoinpoint point
methodsignature signature = (methodsignature)point.getsignature();

method method = signature.getmethod();

class<?> clazz = point.gettarget().getclass();

object args = point.getargs();

hmily hmily = (hmily)method.getannotation(hmily.class);(方法上有hmily註解)

patternenum pattern = hmily.pattern();

hmilytransaction.settargetclass(clazz.getname());

hmilytransaction.settargetmethod(method.getname());

hmilytransaction.setpattern(pattern.getcode());

hmilyinvocation confirminvocation = null;

string confirmmethodname = hmily.confirmmethod();

string cancelmethodname = hmily.cancelmethod();

宅之終極奧義 Ubuntu的root帳號密碼問題

新接觸ubuntu的人 base on debian 大多會因為安裝中沒有提示root密碼而不太清楚為什麼會這樣。如何設定 改變 啟用 root 使用者的密碼?sudo passwd root 為了啟用 root 帳號 也就是 設定乙個口令 使用 sudo passwd root 當你使用完畢後遮蔽...

第一百篇 計算機語言的終極奧義

其實很多時候,我們在做計算機程式設計的時候,都會感覺無賴,為啥,每個專案從調研到除錯都做了很多重複的工作。這個時候,有小夥伴就說,那是因為你沒有用掌握面相物件的程式設計方法,那個時候是因為你還不了解python語言 等等。其實我說的不是這個問題,我們做的工作真的有很大部分都是重複性的工作,不止我重複...

研發與運維一體化,見證終極協同奧義

家家有本難念的經,但是痛卻總是驚人的相似 場景1 某個軟體開發公司裡,所有的設計 開發 測試 運維雖然被分配了不同職能與任務,但是他們都有乙個統一的稱呼 工程師。實際上,他們經常會互相幹一些本不屬於自身職能範圍的工作。公司業務拓展,業務系統功能擴充套件 需求變更,996 的日子成功進化成 007 甚...