gpt4 book ai didi

java - org.springframework.beans.NotReadablePropertyException : Invalid property. Bean属性不可读或具有无效的getter方法

转载 作者:行者123 更新时间:2023-12-02 04:29:58 25 4
gpt4 key购买 nike

我与这个错误作斗争:

Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'customer' of bean class [common.controllers.Index$Login]: Bean property 'customer' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?

Caused by: java.lang.IllegalStateException: JSR-303 validated property 'customer' does not have a corresponding accessor for data binding - check your DataBinder's configuration (bean property versus direct field access)

我无法弄清楚我何时进行了代码更改,这导致了此错误。几天前它刚刚工作。

这是完整的堆栈跟踪:

ERROR | 2015-07-23 15:52:37 | Cannot invoke the action, eventually got an error: java.lang.IllegalStateException: JSR-303 validated property 'customer' does not have a corresponding accessor for data binding - check your DataBinder's configuration (bean property versus direct field access)
ERROR | 2015-07-23 15:52:37 |

! @6mpn2f397 - Internal server error, for (POST) [/] ->

play.api.Application$$anon$1: Execution exception[[IllegalStateException: JSR-303 validated property 'customer' does not have a corresponding accessor for data binding - check your DataBinder's configuration (bean property versus direct field access)]]
at play.api.Application$class.handleError(Application.scala:293) ~[play_2.10.jar:2.2.6]
at play.api.DefaultApplication.handleError(Application.scala:399) [play_2.10.jar:2.2.6]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:268) [play_2.10.jar:2.2.6]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3$$anonfun$applyOrElse$3.apply(PlayDefaultUpstreamHandler.scala:268) [play_2.10.jar:2.2.6]
at scala.Option.map(Option.scala:145) [scala-library.jar:na]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3.applyOrElse(PlayDefaultUpstreamHandler.scala:268) [play_2.10.jar:2.2.6]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$3.applyOrElse(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.6]
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:344) [scala-library.jar:na]
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:343) [scala-library.jar:na]
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library.jar:na]
at play.api.libs.iteratee.Execution$$anon$1.execute(Execution.scala:43) [play-iteratees_2.10.jar:2.2.6]
at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:40) [scala-library.jar:na]
at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:248) [scala-library.jar:na]
at scala.concurrent.Promise$class.complete(Promise.scala:55) [scala-library.jar:na]
at scala.concurrent.impl.Promise$DefaultPromise.complete(Promise.scala:153) [scala-library.jar:na]
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235) [scala-library.jar:na]
at scala.concurrent.Future$$anonfun$map$1.apply(Future.scala:235) [scala-library.jar:na]
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1361) [scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) [scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) [scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) [scala-library.jar:na]
at scala.concurrent.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) [scala-library.jar:na]
Caused by: java.lang.IllegalStateException: JSR-303 validated property 'customer' does not have a corresponding accessor for data binding - check your DataBinder's configuration (bean property versus direct field access)
at play.data.Form.bind(Form.java:344) ~[play-java_2.10.jar:2.2.6]
at play.data.Form.bindFromRequest(Form.java:216) ~[play-java_2.10.jar:2.2.6]
at common.controllers.Index.authenticate(Index.java:191) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$7$$anonfun$apply$7.apply(routes_routing.scala:559) ~[na:na]
at Routes$$anonfun$routes$1$$anonfun$applyOrElse$7$$anonfun$apply$7.apply(routes_routing.scala:559) ~[na:na]
at play.core.Router$HandlerInvoker$$anon$7$$anon$2.invocation(Router.scala:183) ~[play_2.10.jar:2.2.6]
at play.core.Router$Routes$$anon$1.invocation(Router.scala:377) ~[play_2.10.jar:2.2.6]
at play.core.j.JavaAction$$anon$1.call(JavaAction.scala:56) ~[play_2.10.jar:2.2.6]
at play.GlobalSettings$1.call(GlobalSettings.java:64) ~[play_2.10.jar:2.2.6]
at common.actions.IpValidateAction$AuthenticatedAction.call(IpValidateAction.java:62) ~[na:na]
at play.db.jpa.TransactionalAction$1.apply(TransactionalAction.java:20) ~[play-java-jpa_2.10.jar:2.2.6]
at play.db.jpa.TransactionalAction$1.apply(TransactionalAction.java:18) ~[play-java-jpa_2.10.jar:2.2.6]
at play.db.jpa.JPA.withTransactionAsync(JPA.java:177) ~[play-java-jpa_2.10.jar:2.2.6]
at play.db.jpa.TransactionalAction.call(TransactionalAction.java:15) ~[play-java-jpa_2.10.jar:2.2.6]
at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:91) ~[play_2.10.jar:2.2.6]
at play.core.j.JavaAction$$anon$3.apply(JavaAction.scala:90) ~[play_2.10.jar:2.2.6]
at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82) ~[play_2.10.jar:2.2.6]
at play.core.j.FPromiseHelper$$anonfun$flatMap$1.apply(FPromiseHelper.scala:82) ~[play_2.10.jar:2.2.6]
at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:251) ~[scala-library.jar:na]
at scala.concurrent.Future$$anonfun$flatMap$1.apply(Future.scala:249) ~[scala-library.jar:na]
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:32) [scala-library.jar:na]
at play.core.j.HttpExecutionContext$$anon$2.run(HttpExecutionContext.scala:37) ~[play_2.10.jar:2.2.6]
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:42) ~[akka-actor_2.10.jar:2.2.0]
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(AbstractDispatcher.scala:386) ~[akka-actor_2.10.jar:2.2.0]
... 4 common frames omitted
Caused by: org.springframework.beans.NotReadablePropertyException: Invalid property 'customer' of bean class [common.controllers.Index$Login]: Bean property 'customer' 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.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:707) ~[spring-beans.jar:3.2.3.RELEASE]
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:699) ~[spring-beans.jar:3.2.3.RELEASE]
at org.springframework.validation.AbstractPropertyBindingResult.getActualFieldValue(AbstractPropertyBindingResult.java:99) ~[spring-context.jar:3.2.3.RELEASE]
at org.springframework.validation.AbstractBindingResult.rejectValue(AbstractBindingResult.java:105) ~[spring-context.jar:3.2.3.RELEASE]
at play.data.Form.bind(Form.java:338) ~[play-java_2.10.jar:2.2.6]
... 27 common frames omitted
ERROR | 2015-07-23 15:52:37 | REGUEST: POST / GENERATED ERROR: @6mpn2f397: Execution exception in /home/korbeldaniel/git/SVP2/SVP2/target/scala-2.10/src_managed/main/routes_routing.scala:559
App mode 1: centralMode

一般来说,将序列化的 html 表单中的数据绑定(bind)到类 Form<> 的 java 对象时会出现问题。

这是我的登录类:

    public static class Login {

/** The customer. */
@ManyToOne
@Constraints.Required
public Customer customer;

/** The password. */
public String password;

public String loginType;

public Login() {
super();
}

public Login(Customer customer) {
super();
this.customer = customer;
}
public Login(Customer customer, String password, String loginType) {
super();
this.customer = customer;
this.password = password;
this.loginType = loginType;
}
}

这是我的客户类别:

public class Customer {

@Id @GeneratedValue(strategy = GenerationType.IDENTITY) public Long id;

/**
* Instantiates a new customer.
*/
public Customer() {
super();
}

/**
* Instantiates a new customer.
*
* @param new_id the new_id
*/
public Customer(Long new_id) {
super();
id = new_id;
}
}

我没有粘贴表单 View 类,导致绑定(bind)包含客户类/参数的每个表单时发生此错误。

以下是发生错误时的绑定(bind)代码:

Form<Login> filledLoginForm = form(Login.class).bindFromRequest();

我为此使用 playframeworks 表单类。

最佳答案

您的 Login 类需要遵循 javabean 规范。您可以将 Login 的 customer 成员保留为公开,但您必须将其包装在 getter/setter 中:

public Customer getCustomer() {

return this.customer();

}

public void setCustomer(Customer c) {

this.customer = c;

}

您说 play 应该在编译时为您生成这些 getter/setter,但似乎并非如此。我的理解是,它仅对实体/模型类执行此操作,并且我在登录时没有看到 JPA @Entity 注释。让 Login 成为静态类对我来说似乎很奇怪。

关于java - org.springframework.beans.NotReadablePropertyException : Invalid property. Bean属性不可读或具有无效的getter方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31589829/

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