• spring


    方式一:接口

      前置增强      MethodBeforeAdvice

      后置增强      AfterReturningAdvice

      异常抛出增强  ThrowsAdvice

      环绕增强      MethodInterceptor

      注意:还需要在applicationContext.xml文件中进行aop相关的配置

            <aop:config>
            <aop:pointcut expression="execution(public void *User())" id="addoptpointcut"/>
            <aop:advisor advice-ref="logbefore" pointcut-ref="addoptpointcut" />
        </aop:config>

            <aop:config>
            <aop:pointcut expression="execution(* spring_basic.UserService.*(..))" id="userServiceOptPointcut"/>
            <!--
            <aop:advisor advice-ref="exceptionAdvice" pointcut-ref="userServiceOptPointcut" />
             -->
            <aop:advisor advice-ref="logger" pointcut-ref="userServiceOptPointcut" />
        </aop:config>

    方式二:注解

      前置增强      @Before("execution(* service.*.*(..))")

      后置增强      @AfterReturning(pointcut="execution(* service.*.*(..))", returning="result")

      异常抛出增强  @AfterThrowing(pointcut="execution(* service.*.*(..))", throwing="ex")

      环绕增强      @Around("execution(* service.*.*(..))")

      注意:还需要在applicationContext.xml文件中添加如下配置

            <aop:aspectj-autoproxy></aop:aspectj-autoproxy>

    方式三:Scheme

      首先:添加普通的类,里面按要求编写方法

      public class Logger {

        public void before(JoinPoint jp){

        }
        
        public void after(JoinPoint jp, Object result){

        }
        
        public void aterThrowing(JoinPoint jp, Exception ex){

        }
        
        public Object aroundExecute(ProceedingJoinPoint pjp) throws Throwable{

        }

      }

      其次:在applicationContext.xml中配置aop-aspect相关的配置

            <aop:config>
            <aop:pointcut expression="execution(* service.*.*(..))" id="optpointcut"/>
            
            <aop:aspect ref="mylogger">
                <aop:before method="before" pointcut-ref="optpointcut" />
                <aop:after-returning method="after" returning="result" pointcut-ref="optpointcut" />
                <aop:after-throwing method="aterThrowing" throwing="ex" pointcut-ref="optpointcut" />
                <aop:around method="aroundExecute" pointcut-ref="optpointcut"/>
            </aop:aspect>
            
        </aop:config>

  • 相关阅读:
    WORD数据类型数据类型及 Bit,Byte,WORD,DWORD区别和联系
    C++指针探讨 (三) 成员函数指针
    visual c++中常用MFC文件及库文件
    SVN版本管理软件的使用介绍与教程
    C++星号的含义
    ajaxValidator 常见问题解决(传参,中文乱码)
    C++中的常量
    孙鑫老师VC++深入详解第一节课源代码(这样写更好理解)
    C/C++ 头文件 常用头文件功能查询表
    C++指针探讨 (一)数据指针
  • 原文地址:https://www.cnblogs.com/ws1313123/p/6424773.html
Copyright © 2020-2023  润新知