注释和 XML 方式:
注释方式:
最小的xml配置文件:
<!-- Enable autoproxy to pick up all Java files tagged as @Aspect behave like Aspects -->
<aspectj-autoproxy/>
<!-- define bean -->
<!-- Note: MyUselessAspect.java should exist and this class must be tagged as @Aspect -->
<bean id="myUselessAspect" class="...MyUselessAspect" />
XML方式:
最小的XML配置:
<aop:config>
<aop:aspect ref="myUselessAspect">
<!-- this point-cut picks all methods of any return type, from any package/class with any number of Parameters -->
<aop:before method="doSomethingBeforeMethodCall" pointcut="execution(* *.*(..))"/>
<aop:after method="doSomethingAfterMethodCall" pointcut="execution(* *.*(..))"/>
</aop:aspect>
</aop:config>
<!-- No need to Annotate this java Class as @Aspect. Neither you need to define any
Point-cuts or Advices in the Java file. The <aop:config> tag takes care of everything -->
<bean id="myUselessAspect" class="...MyUselessAspect"></bean>
无需更改代码。
Pre-Req:
aop 命名空间必须存在于 XML 文件中