码迷,mamicode.com
首页 > 其他好文 > 详细

AOP案例(二) 异常类切面

时间:2019-12-13 21:32:29      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:imp   npoi   around   etc   pack   ram   col   案例   service   

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案例(二) 异常类切面

标签:imp   npoi   around   etc   pack   ram   col   案例   service   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!