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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容