升级到最新版本后,使用 hibernate-validator(作为 spring-boot-starter-validation 依赖项的一部分)进行了一些验证。我收到此错误:
jakarta.validation.ConstraintDeclarationException: HV000151: A method overriding another method must not redefine the parameter constraint configuration, but method Controller#method(List, String) redefines the configuration of Controller#method(List, String).
当您实现接口方法并在实现中重新定义参数约束时,就会发生这种情况。问题是,当我从实现中删除参数约束时,参数验证不会发生,而理想情况下它应该从接口继承这些约束。
接口:
`ResponseEntity<object> method(@ApiParam(value = "Request Body",required = true) @RequestBody @Valid List<object1> request, @ApiParam("language of the (Exception Detail) response ") @RequestParam(value = "lang",required = false) @Valid String lang);`
实现(去除参数约束后):
@Override public ResponseEntity<object> method( List<object1> request, String lang) { return new ResponseEntity<>(handler.method2(request, lang), httpHeaders, HttpStatus.CREATED); }
在界面签名中使用
@Valid
可以解决这个问题。