Java ControllerAdvice行为不确定性的Spring引导验证
我有以下设置Java ControllerAdvice行为不确定性的Spring引导验证,java,spring,validation,spring-boot,Java,Spring,Validation,Spring Boot,我有以下设置 @ControllerAdvice public class AppControllerAdvice extends ResponseEntityExceptionHandler { @ExceptionHandler({UserInputValidationException.class}) public ResponseEntity<UserInputValidationResponseBody> handleBadInputException(U
@ControllerAdvice
public class AppControllerAdvice extends ResponseEntityExceptionHandler {
@ExceptionHandler({UserInputValidationException.class})
public ResponseEntity<UserInputValidationResponseBody> handleBadInputException(UserInputValidationException ex, WebRequest request) {
return new ResponseEntity<>(
new UserInputValidationResponseBody().setFieldErrors(ex.getFieldErrors()),
HttpStatus.BAD_REQUEST
);
}
}
我想要绑定的POJO上有JSR-303验证注释,Spring在绑定时在请求参数绑定期间正确地验证它们
然而。。。当我让这个设置运行了一段时间后,Spring随机开始绕过@RestController和@ControllerAdvice
现在我似乎收到了org.springframework.web.bind.MethodArgumentNotValidException。。。i、 e.请求被短路
我正在运行Spring Boot 1.5.4.RELEASE
编辑下面的建议,我补充道
给管制员的建议。。。这只会让事情变得更糟。现在绝对没有验证错误-客户端只收到一条空白消息,在当前问题出现之前的一段时间内,这是问题的症状,没有任何代码更改
An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments to which they apply: public org.springframework.http.ResponseEntity com.remo.api.portfolios.PortfolioController.put(java.security.Principal,org.springframework.validation.BindingResult,com.remo.api.portfolios.Portfolio
tl;dr请继续,并确保在BindingResult之前立即声明@RequestBody
@Order(Ordered.HIGHEST_PRECEDENCE)
An Errors/BindingResult argument is expected to be declared immediately after the model attribute, the @RequestBody or the @RequestPart arguments to which they apply: public org.springframework.http.ResponseEntity com.remo.api.portfolios.PortfolioController.put(java.security.Principal,org.springframework.validation.BindingResult,com.remo.api.portfolios.Portfolio