我很难解决这个错误:
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表单中的数据绑定到类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;
}
}
我没有粘贴表单视图类,导致在绑定包含客户类/参数的每个表单时发生此错误。
发生错误时,这是绑定代码:
Form<Login> filledLoginForm = form(Login.class).bindFromRequest();
我使用playframeworks表单类。
答案 0 :(得分:2)
您需要在Login类中遵循javabean规范。您可以将Login的客户成员公开,但您必须将其包装在getter / setter中:
public Customer getCustomer() {
return this.customer();
}
public void setCustomer(Customer c) {
this.customer = c;
}
你说play应该在编译时为你生成那些getter / setter,但似乎并不是。我的理解是,它只对实体/模型类执行此操作,并且我在登录时看不到JPA @Entity注释。让Login成为静态类对我来说也很奇怪。