1、 创建切面类 并注入为bean
使用
//@Component
或
<bean class="com.kdy.aspects.LogAspect" name="aspectname"></bean>
2、关联方法实现代理
<aop:config>
<aop:aspect ref="aspectname">
<aop:pointcut id="cutAllService" expression="execution(* com.kdy.service..*.*(..))"/>
<aop:before method="before" pointcut="execution(* com.kdy.service..*.*(..)) && @annotation(logger)"></aop:before>
<aop:after method="after" pointcut-ref="cutAllService"></aop:after>
<aop:after-returning method="afterReturning" pointcut-ref="cutAllService" returning="returnValue"></aop:after-returning>
<aop:after-throwing method="afterThrow" pointcut-ref="cutAllService" throwing="ex"></aop:after-throwing>
<aop:around method="arround" pointcut-ref="cutAllService"></aop:around>
</aop:aspect>
</aop:config>
为什么推荐使用@Aspectj方式
组合切入点 xml无法实现 @Aspectj 可以