-
Notifications
You must be signed in to change notification settings - Fork 113
异常处理
cmlbeliever edited this page Feb 19, 2017
·
1 revision
全局异常处理封装在com.cml.springboot.framework.exception.ExceptionHandler中,可以在配置文件(config/application.properties)中进行配置
#异常返回处理配置 true表示不对外暴露异常信息,只返回固定的${exception.response.messasge}
exception.response.filter=true
#exception.response.contentType=application/json
exception.response.messasge=exception
- 在controller类中,添加异常处理方法,并添加@ExceptionHandler(Exception.class), @ResponseBody注解
@ExceptionHandler(Exception.class)
@ResponseBody
public String onError(Exception e, HttpServletRequest request) throws Exception {
return "报错了:" + e.getMessage();
}