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>