首页 > 其他 > 详细

AOP案例(二) 异常类切面

时间:2019-12-13 22:20:59      阅读:166      评论:0      收藏:0      [点我收藏+]

package com.jt.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class ExecutionAop {


//如果程序出现了异常,则需要拦截,打印异常信息
@AfterThrowing
(pointcut = "execution(* com.jt.service..*.*(..))",
throwing = "throwable")
public void afterThrow(JoinPoint joinPoint,Throwable throwable) {

Class<?> targetClass = joinPoint.getTarget().getClass();
String methodName = joinPoint.getSignature().getName();
Class<?> throwClass = throwable.getClass();
String msg = throwable.getMessage();
System.out.println("目标对象类型:"+targetClass);
System.out.println("目标方法:"+methodName);
System.out.println("异常类型:"+throwClass);
System.out.println("异常信息:"+msg);
}
}

AOP案例(二) 异常类切面

原文:https://www.cnblogs.com/lizhiwei666/p/12037276.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!