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

首頁(yè) > 學(xué)院 > 開(kāi)發(fā)設(shè)計(jì) > 正文

Spring 的幾種AOP通知

2019-11-10 20:26:51
字體:
來(lái)源:轉(zhuǎn)載
供稿:網(wǎng)友

 

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  //是個(gè)bean

@Aspect           //是個(gè)切面

public classLogging {

       

        /**

         * 在包 com.carry.spring.beans.aop.ArithmeticInterface接口的每一個(gè)實(shí)現(xiàn)類(lèi)的每一個(gè)方法之前打印一句日志

         *

         * */

       

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

        public void beforeMethod(JoinPoint joinpoint){

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

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

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

        }

       

       

        /**

         * 在包 com.carry.spring.beans.aop.ArithmeticInterface接口的每一個(gè)實(shí)現(xiàn)類(lèi)的每一個(gè)方法之后打印一句日志,無(wú)論是否異常出錯(cuò)

         *

         * */

       

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

        public void afterMethod(){

               

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

        }

 

/**

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

 * 可以訪(fǎng)問(wèn)方法的返回值

 *

 * */

       

        @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);

                }

       

}


發(fā)表評(píng)論 共有條評(píng)論
用戶(hù)名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 兴文县| 武隆县| 将乐县| 岑巩县| 吴忠市| 荆门市| 仁化县| 东平县| 淅川县| 景东| 卢龙县| 云安县| 张家界市| 梓潼县| 黎平县| 荥经县| 三河市| 宿松县| 昌图县| 兴海县| 和静县| 拜城县| 南城县| 昌吉市| 新安县| 阳原县| 辉县市| 罗城| 泗洪县| 教育| 隆昌县| 翁牛特旗| 和硕县| 开江县| 梁河县| 淳化县| 湖北省| 巨野县| 县级市| 化德县| 三台县|