- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我构建了一个RestControlerAdvise
:
@RestControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class ExceptionControllerAdvice {
@ExceptionHandler({DocumentAlreadyExistsException.class})
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public cat.gencat.ctti.canigo.arch.web.rs.model.Error handleException(DocumentAlreadyExistsException e) {
cat.gencat.ctti.canigo.arch.web.rs.model.Error error = new cat.gencat.ctti.canigo.arch.web.rs.model.Error();
error.setCode(HttpStatus.BAD_REQUEST.value());
error.setMessage(e.getMessage());
return error;
}
}
尽管如此,即使我提出 DocumentAlreadyExistException
,它也从未达到。
启动时检测到:
2018-08-20 17:08:25.791 INFO 4941 --- [ main] .m.m.a.ExceptionHandlerExceptionResolver : Detected @ExceptionHandler methods in exceptionControllerAdvice
有什么想法吗?
最佳答案
我在我的应用程序中运行了相同的代码,并且工作正常,另请注意
@ExceptionHandler methods on the Controller are always selected before those on any @ControllerAdvice instance. It is undefined what order controller-advices are processed.
@RestControllerAdvice
@Order(Ordered.HIGHEST_PRECEDENCE)
public class CustomExceptionHandler {
@ExceptionHandler(value={Exception.class})
@ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
public final ErrorMessage exceptionHandler(Exception e)
{
ErrorMessage msg=new ErrorMessage();
msg.setError("its an error");
return msg;
}
另请参阅以下链接以获取更多信息: https://spring.io/blog/2013/11/01/exception-handling-in-spring-mvc
关于java - Spring-boot:未达到 RestControllerAdvise,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51933752/
我正在配置自定义错误处理,以便将每个错误请求记录到我的 API。在我的场景中,了解请求中传递的有效负载非常重要,这样我就可以根据需要修复/测试/重新处理它。 我已经构建了一个简单的@RestContr
我构建了一个RestControlerAdvise: @RestControllerAdvice @Order(Ordered.HIGHEST_PRECEDENCE) public class Exc
在 Spring 4.x 中,如果您使用扩展 ResponseEntityExceptionHandler 的 @RestControllerAdvise(或 @ControllerAdvice),则
我是一名优秀的程序员,十分优秀!