zoukankan      html  css  js  c++  java
  • Spring AOP统一异常处理

    1、添加依赖

    1         <dependency>  
    2             <groupId>org.springframework.boot</groupId>
    3             <artifactId>spring-boot-starter-aop</artifactId>
    4         </dependency>
    5         <dependency>
    6             <groupId>cglib</groupId>
    7             <artifactId>cglib</artifactId>
    8             <version>2.2.2</version>
    9         </dependency>

    2、在application.properties中添加配置

    1 #aop
    2 spring.aop.proxy-target-class=true

    3、具体代码

     1 package cn.creditcrest.finance.rest.advice;
     2 
     3 import org.aspectj.lang.JoinPoint;
     4 import org.aspectj.lang.annotation.AfterThrowing;
     5 import org.aspectj.lang.annotation.Aspect;
     6 import org.aspectj.lang.annotation.Pointcut;
     7 import org.slf4j.Logger;
     8 import org.slf4j.LoggerFactory;
     9 import org.springframework.stereotype.Component;
    10 
    11 @Aspect
    12 @Component
    13 public class GlobalAspect {
    14      
    15     @Pointcut("execution(public * cn.creditcrest.finance..*.*(..))")  
    16     public void pcMethod(){};  
    17     
    18     @AfterThrowing(pointcut = "pcMethod()",throwing="e")  
    19     public void doException(JoinPoint jp,Throwable e){  
    20         if(e!=null){  
    21             Logger logger = LoggerFactory.getLogger(jp.getSignature().getClass());
    22              logger.error(e.getMessage(),e);
    23         }  
    24     }
    25 
    26 }
  • 相关阅读:
    django的命令, 配置,以及django使用mysql的流程
    vue中局部组件的使用
    Chapter14【Collection、泛型】
    泛型
    集合遍历的方式(迭代器和增强for)
    Collection集合
    集合
    数组
    包装类
    基本类型与字符串之间的转换
  • 原文地址:https://www.cnblogs.com/zq-boke/p/6922831.html
Copyright © 2011-2022 走看看