spring AOP 學習筆記

來源:互聯網
上載者:User
術語理解:

 

cross-cutting concerns:散落在業務中,但又與業務無關的程式碼片段。

 

|

|識別為Aspect

|

v

 

Aspect:通過整理cross-cutting concerns,需要從中識別出可重用的、功能單一的切面,例如日誌/許可權檢查切面等。

 

|

|============分割線:上面是業務中的概念,下面是代碼中的概念==========

|

|實現為Advisor(主要是PointcutAdvisor = Pointcut  +Advise)

|

v

 

Pointcut:觸發時機,即做的前提條件,通常需要target/client符合某些情況時才觸發Advise。例如target的類名/方法名符合指定Regex時觸發Advise。Pointcut支援取交集/並集。+Advise:觸發內容,即做什麼。例如日誌動作/許可權檢查動作的具體實現。|||_ _ _ Joinpoint: Advise的屬性,表明做什麼的時刻,spring只能在以下情況中任選:target的方法前/後/環繞/拋出異常時。Spring AOP的核心思想是代理:client ----透明調用目標----> proxy ----織入目標----> target                                                            |                                                            v                                               改變行為 / 增加行為                                                      |            |                                                     v             v                                   PointcutAdvisor     IntroductionAdvisor配置方式:ProxyBean|||_ _ _ proxyInterfaces:targetInterface|||_ _ _ target:targetBean|||_ _ _ interceptorNames:可以填入Advise/ Advisor/ Interceptor直接填Advise即省略了Pointcut,表示proxyInterfaces中聲明的所有方法都要觸發Advise。Interceptor和Advisor類似,只不過前者是AOP Alliance制定的標準,後者是spring自己的標準。PointcutAdvisor(以DefaultPointcutAdvisor為例)|||_ _ _ pointcut:pointcutBean|||_ _ _ advise:adviseBean動態改變了targetInterface中描述的行為,在pointcutBean中指定了觸發時機,在adviseBean中指定了觸發內容。IntroductionAdvisor(以DefaultIntroductionAdvisor為例)|||_ _ _ constructor-arg0:IntroductionBean|||_ _ _ constructor-arg1:IntroductionInterface為target動態增加了IntroductionInterface中描述的行為,其具體實現在IntroductionBean中。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.