新建GlobalExceptionResolver
public class GlobalExceptionResolver implements HandlerExceptionResolver{
@Override
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
Exception exception) {
response.setContentType("application/json;charset=utf-8");
log.error("访问" + request.getRequestURI() + " 发生错误, 错误信息:" + ex);
ReturnUtils.returnError(response,"网络开小差了");
return null;
}
spring配置文件中配置刚才新建的类,或者加上@Component注解
<bean class="com.saas.exception.GlobalExceptionResolver" />