AOP Config

What is AOP?

AOP: Aspect-Oriented Programming(面向切片編程).
weaving, is the perfect and exact word to describe it. Please consider the following situation.
You have a bean A but it is not fully functional. Then there are 2 options for you: to rewrite bean A and complete it as expect; Or you can choose AOP.
To AOP, you write another bean named B(Or beans named B, C, D...), which finishes the rest of the functions that you expect in bean A. AOP helps you weave bean B(C, D, ...) into bean A. Finally we get a fully-functional bean A that is advised. What you should do next is to config it to make Spring knows.

1. XML config

Defect: Can only support "singleton" bean.
All the aspect, pointcut and advice should be included in <aop:config...> element.

<aop:config...>
    <aop:aspect id="xxx" ref="ref_bean_id" order="2">
        <aop:pointcut.../>
        <aop:declare-parent.../>
        <!-- advice handle. -->
        <aop:before pointcut="xx" method="xxxMethod()".../> <!-- pointcut can be replaced by pointcut-ref. -->
        <aop:after.../>
        <aop:after-returning returning="a_formal_param".../> 
        <aop:after-throwing throwing="a_formal_param".../>
        <aop:around.../>
    </aop:aspect>
     <!-- pointcut can be shared by aspects, if defined here. -->
    <aop:pointcut id="pointcut_id" expression="execution(* com.bupt.huang.service.*.*(...))".../> 
    <aop:advisor.../>
</aop:config>

2. @AspectJ config

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容