总错误处理,是为了在程序运行时代码出错能及时在控制台看出错误信息。
1.
springMVC配置文件中:
--------
2.controller包中:
新建类FrameControllerAdvice
package isa.qa.frame.controller; import org.apache.log4j.Logger; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ControllerAdvice; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.context.request.NativeWebRequest; @ControllerAdvice public class FrameControllerAdvice { protected static Logger logger = Logger.getLogger(FrameControllerAdvice.class); @ExceptionHandler(Exception.class) //@ResponseStatus(HttpStatus.BAD_REQUEST) public ResponseEntity<String> processUnauthenticatedException(NativeWebRequest request,Exception e) { logger.error(e.getMessage()); e.printStackTrace(); return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR); } }
时间: 2024-10-23 20:24:12