• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Spring AOP的半注解和全注解模式是什么意思

武飞扬头像
PHP中文网
帮助10

学新通技术网

<bean   class="com.lagou.edu.utils.LogUtils"></bean>
<aop:config>
    <aop:aspect   ref="logUtils">
    </aop:aspect>
</aop:config>

修改成以下注解

学新通技术网

&lt;!&ndash;切入点锁定我们感兴趣的方法,使用aspectj语法表达式&ndash;&gt;
&lt;!&ndash;<aop:pointcut   expression="execution(* *..*.*(..))"/>&ndash;&gt;
 <aop:pointcut   expression="execution(* com.lagou.edu.service.impl.TransferServiceImpl.*(..))"/>

修改注解,加入一个空的方法

学新通技术网

&lt;!&ndash;方位信息,pointcut-ref关联切入点&ndash;&gt;
&lt;!&ndash;aop:before前置通知/增强&ndash;&gt;
<aop:before method="beforeMethod" pointcut-ref="pt1"/>
&lt;!&ndash;aop:after,最终通知,无论如何都执行&ndash;&gt;
&lt;!&ndash;aop:after-returnning,正常执行通知&ndash;&gt;
<aop:after-returning method="successMethod" returning="retValue"/>
&lt;!&ndash;aop:after-throwing,异常通知&ndash;&gt;

修改注解

学新通技术网

学新通技术网

 aop:around method="arroundMethod" pointcut-ref="pt1"/>

学新通技术网

把原来的xml配置注释掉,只需在xml配置

<!--开启aop注解驱动
    proxy-target-class:true强制使用cglib

-->
<aop:aspectj-autoproxy/>

这是半注解模式,如果需要开启全注解模式,

只需在配置类中加入@EnableAspectJAutoProxy //开启spring对注解AOP的支持

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tangbihik
系列文章
更多 icon
同类精品
更多 icon
继续加载