介绍
本篇文章为大家展示了Spring AOP中什么是半注解和全注解模式,内容简明扼要并且容易理解,绝对能使你眼前一亮,通过这篇文章的详细介绍希望你能有所收获。
& lt; bean id=發ogUtils",类=癱om.lagou.edu.utils.LogUtils"祝辞& lt;/bean> & lt; aop: config> ,,,& lt; aop: aspect id=發ogAspect", ref=發ogUtils"比; ,,,& lt;/aop: aspect> & lt;/aop: config>
修改成以下注解
,lt; !, mdash;切入点锁定我们感兴趣的方法,使用aspectj语法表达式,mdash;和gt; ,lt; !, mdash; & lt; aop: pointcut id=皃t1",表达=爸葱?*,* . . *。*(. .))“/祝辞,mdash;和gt;
,& lt; aop: pointcut id=皃t1",表达=爸葱?* com.lagou.edu.service.impl.TransferServiceImpl。*(. .)“/祝辞
修改注解,加入一个空的方法
,lt; !, mdash;方位信息,pointcut-ref关联切入点,mdash;和gt; ,lt; !, mdash; aop:前之前置通知/增强,mdash;和gt; & lt; aop: before 方法=癰eforeMethod", pointcut-ref=皃t1"/比; ,lt; !, mdash; aop:之后,最终通知,无论如何都执行,mdash;和gt; ,lt; !, mdash; aop: after-returnning,正常执行通知,mdash;和gt; & lt; aop: after-returning 方法=皊uccessMethod",返回=皉etValue"/比; ,lt; !, mdash; aop:投掷,异常通知,mdash;和gt;
修改注解
,aop: around 方法=癮rroundMethod", pointcut-ref=皃t1"/祝辞
把原来的xml配置注释掉,只需在xml配置
& lt; !开启aop注解驱动 ,,,proxy-target-class:真强制使用cglib ——比; & lt; aop: aspectj-autoproxy/祝辞
这是半注解模式,如果需要开启全注解模式,
只需在配置类中加入@EnableAspectJAutoProxy//开启春天对注解aop的支持
上述内容就是spring aop中什么是半注解和全注解模式,你们学到知识或技能了吗?如果还想学到更多技能或者丰富自己的知识储备,欢迎关注行业资讯频道。