国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

Spring 的幾種AOP通知

2019-11-10 23:28:54
字體:
來源:轉載
供稿:網友

 

package com.carry.sPRing.beans.aop;

 

import java.awt.List;

import java.util.Arrays;

 

import org.aspectj.lang.JoinPoint;

import org.aspectj.lang.annotation.After;

import org.aspectj.lang.annotation.AfterReturning;

import org.aspectj.lang.annotation.AfterThrowing;

import org.aspectj.lang.annotation.Aspect;

import org.aspectj.lang.annotation.Before;

import org.springframework.stereotype.Component;

 

 

@Component  //是個bean

@Aspect           //是個切面

public classLogging {

       

        /**

         * 在包 com.carry.spring.beans.aop.ArithmeticInterface接口的每一個實現類的每一個方法之前打印一句日志

         *

         * */

       

        @Before("execution(public intcom.carry.spring.beans.aop.ArithmeticInterface.*(..))")

        public void beforeMethod(JoinPoint joinpoint){

                StringmethodName=joinpoint.getSignature().getName();    //得到當前方法的名字 

                Object[] args=joinpoint.getArgs();                        //得到方法的參數

                System.out.println("The Method:"+methodName+" begin "+Arrays.asList(args));

        }

       

       

        /**

         * 在包 com.carry.spring.beans.aop.ArithmeticInterface接口的每一個實現類的每一個方法之后打印一句日志,無論是否異常出錯

         *

         * */

       

        @After("execution(public intcom.carry.spring.beans.aop.ArithmeticInterface.*(..))")

        public void afterMethod(){

               

                System.out.println("The Method end");

        }

 

/**

 * 返回通知,在方法正常結束后執行的代碼,有異常不顯示

 * 可以訪問方法的返回值

 *

 * */

       

        @AfterReturning(value="execution(public intcom.carry.spring.beans.aop.ArithmeticInterface.*(..))",

                        returning="res")

        public void returnMethod(JoinPoint joinPoint,Objectres){

                String  mathodName=joinPoint.getSignature().getName();

                System.out.println("The Method returnMethod"+".."+mathodName+".."+res);

        }

        /**

         * 異常通知

         *

         *

         * */

               

                @AfterThrowing(value="execution(public intcom.carry.spring.beans.aop.ArithmeticInterface.*(..))",

                                throwing="thr")

                publicvoid returnMethod(JoinPoint joinPoint,Exception thr){

                        String  mathodName=joinPoint.getSignature().getName();

                        System.out.println("The Method returnMethod"+".."+mathodName+".."+thr);

                }

       

}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 安庆市| 长宁区| 积石山| 霍邱县| 万年县| 安徽省| 河东区| 衡东县| 福贡县| 周至县| 油尖旺区| 昭觉县| 贵阳市| 秭归县| 永新县| 海伦市| 宽甸| 钟山县| 开远市| 怀化市| 新蔡县| 晋州市| 德庆县| 赤城县| 田阳县| 遵义县| 吴堡县| 阿克陶县| 疏勒县| 望江县| 瓦房店市| 五莲县| 汉川市| 瑞昌市| 博野县| 邵武市| 西林县| 保定市| 漠河县| 鄢陵县| 获嘉县|