Spring Boot HV000151:Hibernate验证程序异常,未从接口继承约束

lsmepo6l  于 5个月前  发布在  Spring
关注(0)|答案(1)|浏览(62)

升级到最新版本后,使用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); }

fkvaft9z

fkvaft9z1#

在接口签名中使用@Valid可以解决这个问题。

相关问题