@Aspect
@Component
public class ErrAspect {
private static final Logger log = LoggerFactory.getLogger(ErrAspect.class);
@Autowired
private SysErrLogMapper errLogMapper;
// 配置织入点
@Pointcut("within(com.haxk..*)")
public void logPointCut()
{
}
@AfterThrowing(value = "logPointCut()", throwing = "e")
public void getErr(JoinPoint joinPoint, Exception e){
//方法名
String name = joinPoint.getSignature().getName();
//方法所属类
String declaringTypeName = joinPoint.getSignature().getDeclaringTypeName();
ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
String ip = "";
String method = "";
if(null != requestAttributes){
// 请求地址
ip = IpUtils.getIpAddr(ServletUtils.getRequest());
利用AOP捕获并记录全局异常 具体到方法和参数
最新推荐文章于 2022-06-29 17:47:35 发布
本文介绍如何借助AOP的@AfterThrowing注解,捕获应用程序中的异常,并详细记录包括方法和参数在内的信息,实现日志记录到数据库。
摘要由CSDN通过智能技术生成