一、先看你的全局异常处理器的ExceptionConfiguration类有没有被引入到ioc容器中,
1、ExceptionConfiguration类上有没有@RestConfiguration注解,没有就请加上
2、ExceptionConfiguration类可能没被启动类烧苗到
这种情况大多出现在ExceptionConfiguration类不在本项目上,
如果在别的模块如公共包,请在启动类上加上
@MapperScan("com.baidu.common")
二、ExceptionConfiguration类被引入到ioc容器中,但还是不起作用,这时候要看你的controller层的所有方法有没有被aop切入,做了环绕通知,并且在通知中对异常进行了抓取,这时候全局异常处理器就捕捉不到异常了,因为异常都在环绕通知这被抓光了.解决的办法就把异常抛出去!
@Around("execution(* com.baidu.controller.*.*(..))")
public Object aroundAdvice(ProceedingJoinPoint point) {
Object[] args = point.getArgs();
try {
return point.proceed(args);
} catch (Throwable e) {
return null;
}
}