AOP案例 异常类切面
Posted lizhiwei666
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了AOP案例 异常类切面相关的知识,希望对你有一定的参考价值。
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案例 异常类切面的主要内容,如果未能解决你的问题,请参考以下文章