测试要求在注入失败时做默认处理,但是我无法捕获注入时的异常,页面直接挂了,求助。
https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc
---update--
比如你在代码中抛出了一个UserNotExistException异常,下面的代码就可以直接捕获
@ControllerAdvice
@ResponseBody
public class GlobalExceptionHandler {
@ResponseStatus(HttpStatus.NOT_FOUND)
@ExceptionHandler(UserNotExistException.class)
public WrapResponse handleUserNotExist(){
return new WrapResponse().failure("用户名不存在");
}
}