zoukankan      html  css  js  c++  java
  • 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/>
  • 相关阅读:
    【学习笔记】最小表示法
    bzoj1912【Apio2010】patrol 巡逻
    hdu1057
    hdu1056
    hdu1055
    hdu1054
    hdu1053
    hdu1052
    hdu1051
    hdu1050
  • 原文地址:https://www.cnblogs.com/wpy188/p/12391314.html
Copyright © 2011-2022 走看看