Fork me on GitHub

【09-27】Spring 学习笔记

SpringMVC 配置全局异常处理器

import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 配置全局SpringMVC异常处理方法,该类应该配置SpringMVC能够扫描的包中
 */
@ControllerAdvice
public class GlobalExceptionHandler {
	@ResponseBody
	@ExceptionHandler(Exception.class)
	public String handleException(Exception e, HttpServletResponse response) {
		response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
		return e.getMessage();
	}

}
posted @ 2016-09-27 23:15  aloha_world  阅读(102)  评论(0编辑  收藏  举报