spring-boot global exception capture

spring-boot global exception capture

It can be used for unified return and internationalization of error information after SpringMVC request, and exception handling components can also be developed based on this type of extension

configure

@ControllerAdvice
public class CloudExceptionHandler {
	@ExceptionHandler(value = Exception.class)
	public void defaultExceptionHandler(HttpServletRequest request, Exception e){
		//打印异常信息:
		e.printStackTrace();
		System.out.println("CloudExceptionHandler.defaultExceptionHandler()");
		
		//TODO 可返回 json 需要加 @ResponseBody
		
		//TODO 可返回 视图 ModelAndView
	}
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325059844&siteId=291194637