zoukankan      html  css  js  c++  java
  • 关于Spring的AOP的通知类型(在AspectJ)的情况下使用

    package com.layne.spring.aspect.aspects;
    
    import org.aspectj.lang.JoinPoint;
    import org.aspectj.lang.ProceedingJoinPoint;
    import org.aspectj.lang.annotation.After;
    import org.aspectj.lang.annotation.AfterReturning;
    import org.aspectj.lang.annotation.AfterThrowing;
    import org.aspectj.lang.annotation.Around;
    import org.aspectj.lang.annotation.Aspect;
    import org.aspectj.lang.annotation.Before;
    import org.aspectj.lang.annotation.Pointcut;
    
    @Aspect //表示当前POJO类为切面
    public class MyAspect {
        
        //定义前置通知方法
        @Before("execution(* *..ISomeService.doSome(..))")
        public void myBefore(){
            System.out.println("执行前置通知方法myBefore");
        }
        //定义前置通知方法
        @Before(value = "execution(* *..ISomeService.doSome(..))")
        public void myBefore(JoinPoint jp){  //所有通知类型下,都有这个参数
            System.out.println("执行前置通知方法   Jp="+jp);
        }
        //定义前置通知方法
        @AfterReturning("execution(* *..ISomeService.doSecond(..))")
        public void afterReturning(){
            System.out.println("执行后置通知方法  ``````");
        }
        //定义后置通知方法
        @AfterReturning(value = "execution(* *..ISomeService.doSecond(..))",returning="result")
       public void afterReturning(Object result){
            System.out.println("执行后置通知方法  result="+result);
        }
        //环绕通知方法
        @Around("execution(* *..ISomeService.doThird(..))")
       public Object MyAround(ProceedingJoinPoint pjp) throws Throwable{
            System.out.println("执行目标方法之前执行···000000");
            Object proceed = pjp.proceed();
            String upperCase = ((String)proceed).toUpperCase();
            System.out.println("执行目标方法之后执行····00000");
            return upperCase;
            
        }
        //异常通知
        @AfterThrowing(value="execution(* *..ISomeService.doSome(..))",throwing="ex")
        public void myThrows(Exception ex){
            System.out.println("执行异常通知······ex="+ex.getMessage());
        }
        
        //最终通知
        @After("doSomePointCut()")
        public void myAfter(){
            System.out.println("执行最终通知+++++++00999999999000+++++++");
        }
        //定义通知的切点
        @Pointcut(value="execution(* *..ISomeService.doSome(..))")
        private void doSomePointCut(){};
        
    }
  • 相关阅读:
    alkhaser学习笔记(一)Anti Debug
    8086 汇编指令手册查询(转)
    QueryUserAPC Ring3下 APC注入
    内存分配(malloc,new,VirtualAlloc,HeapAlloc,GlobalAlloc,LocalAlloc)区别与注意
    error C2220: 警告被视为错误 没有生成“object”文件 (转)
    消息队列
    分页存储过程(对有主键的表效率极高)
    asp.net vs2010 设计报表rdlc时,未能加载文件或程序集
    【翻译】创建ViewState特征的自动ViewState属性
    中英文字符的截取
  • 原文地址:https://www.cnblogs.com/flytogalaxy/p/7404918.html
Copyright © 2011-2022 走看看