gpt4 book ai didi

java - NotReadablePropertyException : Invalid property '' when validating list of string

转载 作者:太空宇宙 更新时间:2023-11-04 11:11:39 26 4
gpt4 key购买 nike

我正在使用 spring boot 1.5.4.RELEASE 验证请求的内容

@RequestMapping(method = PATCH, value = "/{uniqueId}", produces = APPLICATION_JSON_VALUE)
public ResponseEntity<UserResource> setGlobalRoles(@PathVariable("uniqueId") String uniqueId,
@Valid @RequestBody UserPatch patch) { ... }

该类看起来像:

public class UserPatch {
@Valid
private List<@GlobalRoleExists String> globalRoles = new ArrayList<>();

...

public List<String> getGlobalRoles() {
return globalRoles;
}

public void setGlobalRoles(List<String> globalRoles) {
this.globalRoles = globalRoles;
}

当列表中的某个元素对于约束无效时,会引发以下错误。

org.springframework.beans.NotReadablePropertyException: Invalid property 'globalRoles[1].<collection element>' of bean class [com.app.UserPatch]: Bean property 'globalRoles[1].<collection element>' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:633) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.beans.AbstractNestablePropertyAccessor.getPropertyValue(AbstractNestablePropertyAccessor.java:624) ~[spring-beans-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:99) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.validation.AbstractBindingResult.getRawFieldValue(AbstractBindingResult.java:283) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.validation.beanvalidation.SpringValidatorAdapter.getRejectedValue(SpringValidatorAdapter.java:268) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.validation.beanvalidation.SpringValidatorAdapter.processConstraintViolations(SpringValidatorAdapter.java:148) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.validation.beanvalidation.SpringValidatorAdapter.validate(SpringValidatorAdapter.java:117) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.validation.DataBinder.validate(DataBinder.java:891) ~[spring-context-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.validateIfApplicable(AbstractMessageConverterMethodArgumentResolver.java:270) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:133) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:158) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:128) ~[spring-web-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:967) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:901) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843) ~[spring-webmvc-4.3.10.RELEASE.jar:4.3.10.RELEASE]

我注意到路径“globalRoles[1]”。由 hibernate (org.hibernate.validator.internal.engine.path.NodeImpl) 生成,但我不知道我是否遗漏了某些内容,或者是否无法做到这一点。

最佳答案

从 Spring Boot 1.4.x 升级到 1.5.6 时,我遇到了同样的问题。

此问题记录在 Spring issue tracker 中是由发生验证失败时 Hibernate 5.3.x 中生成的字符串发生更改引起的。

Spring Framework 4.3.11 应该包含修复程序,同时您可以显式指定对 Hibernate 版本 5.2.5 的依赖项(即 compile group: 'org.hibernate', name: 'hibernate-validator', version: '5.2.5.Final'
如果您使用 Gradle)。

关于java - NotReadablePropertyException : Invalid property '<collection element>' when validating list of string,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45941624/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com