在 applicationContext.xml 中
- 配置切面myAspect,即為日志類。其中有l(wèi)og()方法,為記錄日志。
<bean id="myAspect" class="xx.xx.MyAspect"></bean>
- 配置UserDaoImpl,其中的save()方法為切入點。
<bean id="userDao" class="xx.xx.UserDaoImpl"></bean>
- 配置AOP,在save()之前執(zhí)行l(wèi)og()方法
<aop:config>
<aop:aspect ref="myAspect">
<aop:before method="log" pointcut="execution(public void xx.xx.UserDaoImpl.save())"/>
</aop:aspect>
</aop:config>
若是被代理的類UserDaoImpl實現(xiàn)了接口,則spring使用動態(tài)代理,
若UserDaoImpl是沒有實現(xiàn)接口的類,則spring使用cglib