• Spring-AOP的三种方式


    <!--方式一-->
    <!--使用原生Spring Api接口-->
    <!--配偶AOP:需要导入aop的约束-->
    <aop:config>
    <!--切入点,expression 表达式.execution(要执行的位置!)-->
    <aop:pointcut id="pointcut" expression="execution(* cn.scitc.service.MethedDaoImpl.MethedDaoImpl.*(..))"/>
    <!--执行环绕增强-->
    <aop:advisor advice-ref="beforeLog" pointcut-ref="pointcut"/>
    <aop:advisor advice-ref="afterlog" pointcut-ref="pointcut"/>
    </aop:config>

    <!--方式二 自定义实现aop-->
    <bean id="DiyMethed" class="cn.scitc.diy.DiyMethed"/>
    <aop:config>
    <aop:aspect ref="DiyMethed">
    <!--切入点-->
    <aop:pointcut id="pointCut" expression="execution(* cn.scitc.service.MethedDaoImpl.MethedDaoImpl.*(..))"/>
    <!--通知-->
    <aop:before method="before" pointcut-ref="pointCut"/>
    <aop:after method="after" pointcut-ref="pointCut"/>
    </aop:aspect>
    </aop:config>

    <!--方式三 注解-->
    <bean id="diyAnnocade" class="cn.scitc.diy.DiyAnnocade"/>

    //方式三
    @Aspect
    public class DiyAnnocade {

    @Before("execution(* cn.scitc.service.MethedDaoImpl.MethedDaoImpl.*(..))")
    public void before(){
    System.out.println("==========方法执行之前===========");
    }

    @After("execution(* cn.scitc.service.MethedDaoImpl.MethedDaoImpl.*(..))")
    public void after(){
    System.out.println("==========方法执行之后===========");
    }
    }


    <!--开启注解支持-->
    <aop:aspectj-autoproxy/>
  • 相关阅读:
    oracle_使用udev绑定磁盘方法
    Android studio实现简单的CRUD
    Android Studio无法打印Logout日志
    迭代法求平方根
    实现Hibernate框架的CRUD
    Android Studio连接真机调试
    Java项目学习笔记(一)
    绝对路径${pageContext.request.contextPath}
    request、response的setCharacterEncoding与response的setContentType
    java中的@Override标签
  • 原文地址:https://www.cnblogs.com/wpy188/p/12391314.html
Copyright © 2020-2023  润新知