org.springframework.beans.NotReadablePropertyException:无效属性。 Bean 属性 不可读或具有无效的 getter 方法
org.springframework.beans.NotReadablePropertyException: Invalid property. Bean property is not readable or has an invalid getter method
我为这个错误而苦恼:
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: 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$$anonfun$applyOrElse.apply(PlayDefaultUpstreamHandler.scala:268) [play_2.10.jar:2.2.6]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$$anonfun$applyOrElse.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.applyOrElse(PlayDefaultUpstreamHandler.scala:268) [play_2.10.jar:2.2.6]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun.applyOrElse(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.6]
at scala.concurrent.Future$$anonfun$recoverWith.apply(Future.scala:344) [scala-library.jar:na]
at scala.concurrent.Future$$anonfun$recoverWith.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.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.apply(Future.scala:235) [scala-library.jar:na]
at scala.concurrent.Future$$anonfun$map.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$$anonfun$applyOrElse$$anonfun$apply.apply(routes_routing.scala:559) ~[na:na]
at Routes$$anonfun$routes$$anonfun$applyOrElse$$anonfun$apply.apply(routes_routing.scala:559) ~[na:na]
at play.core.Router$HandlerInvoker$$anon$$anon.invocation(Router.scala:183) ~[play_2.10.jar:2.2.6]
at play.core.Router$Routes$$anon.invocation(Router.scala:377) ~[play_2.10.jar:2.2.6]
at play.core.j.JavaAction$$anon.call(JavaAction.scala:56) ~[play_2.10.jar:2.2.6]
at play.GlobalSettings.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.apply(TransactionalAction.java:20) ~[play-java-jpa_2.10.jar:2.2.6]
at play.db.jpa.TransactionalAction.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.apply(JavaAction.scala:91) ~[play_2.10.jar:2.2.6]
at play.core.j.JavaAction$$anon.apply(JavaAction.scala:90) ~[play_2.10.jar:2.2.6]
at play.core.j.FPromiseHelper$$anonfun$flatMap.apply(FPromiseHelper.scala:82) ~[play_2.10.jar:2.2.6]
at play.core.j.FPromiseHelper$$anonfun$flatMap.apply(FPromiseHelper.scala:82) ~[play_2.10.jar:2.2.6]
at scala.concurrent.Future$$anonfun$flatMap.apply(Future.scala:251) ~[scala-library.jar:na]
at scala.concurrent.Future$$anonfun$flatMap.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.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 形式绑定到 class java 对象时会出现问题 Form<>
这是我的登录信息class:
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;
}
}
这是我的客户class:
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;
}
}
我没有粘贴表单视图 class,导致在绑定包含客户 class/parameter 的每个表单时发生此错误。
错误时的绑定代码如下:
Form<Login> filledLoginForm = form(Login.class).bindFromRequest();
为此我使用 playframeworks 形式 class。
您需要在登录时遵循 javabean 规范 class。您可以保留 Login public 的客户成员,但您必须将其包装在 getter/setter:
public Customer getCustomer() {
return this.customer();
}
public void setCustomer(Customer c) {
this.customer = c;
}
你说 play 应该在编译时为你生成那些 getters/setters,但似乎不是。我的理解是,它只对 entity/model classes 执行此操作,而且我在登录时没有看到 JPA @Entity 注释。同样让登录成为静态 class 对我来说似乎很奇怪。
我为这个错误而苦恼:
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: 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$$anonfun$applyOrElse.apply(PlayDefaultUpstreamHandler.scala:268) [play_2.10.jar:2.2.6]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$$anonfun$applyOrElse.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.applyOrElse(PlayDefaultUpstreamHandler.scala:268) [play_2.10.jar:2.2.6]
at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun.applyOrElse(PlayDefaultUpstreamHandler.scala:264) [play_2.10.jar:2.2.6]
at scala.concurrent.Future$$anonfun$recoverWith.apply(Future.scala:344) [scala-library.jar:na]
at scala.concurrent.Future$$anonfun$recoverWith.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.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.apply(Future.scala:235) [scala-library.jar:na]
at scala.concurrent.Future$$anonfun$map.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$$anonfun$applyOrElse$$anonfun$apply.apply(routes_routing.scala:559) ~[na:na]
at Routes$$anonfun$routes$$anonfun$applyOrElse$$anonfun$apply.apply(routes_routing.scala:559) ~[na:na]
at play.core.Router$HandlerInvoker$$anon$$anon.invocation(Router.scala:183) ~[play_2.10.jar:2.2.6]
at play.core.Router$Routes$$anon.invocation(Router.scala:377) ~[play_2.10.jar:2.2.6]
at play.core.j.JavaAction$$anon.call(JavaAction.scala:56) ~[play_2.10.jar:2.2.6]
at play.GlobalSettings.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.apply(TransactionalAction.java:20) ~[play-java-jpa_2.10.jar:2.2.6]
at play.db.jpa.TransactionalAction.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.apply(JavaAction.scala:91) ~[play_2.10.jar:2.2.6]
at play.core.j.JavaAction$$anon.apply(JavaAction.scala:90) ~[play_2.10.jar:2.2.6]
at play.core.j.FPromiseHelper$$anonfun$flatMap.apply(FPromiseHelper.scala:82) ~[play_2.10.jar:2.2.6]
at play.core.j.FPromiseHelper$$anonfun$flatMap.apply(FPromiseHelper.scala:82) ~[play_2.10.jar:2.2.6]
at scala.concurrent.Future$$anonfun$flatMap.apply(Future.scala:251) ~[scala-library.jar:na]
at scala.concurrent.Future$$anonfun$flatMap.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.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 形式绑定到 class java 对象时会出现问题 Form<>
这是我的登录信息class:
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;
}
}
这是我的客户class:
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;
}
}
我没有粘贴表单视图 class,导致在绑定包含客户 class/parameter 的每个表单时发生此错误。
错误时的绑定代码如下:
Form<Login> filledLoginForm = form(Login.class).bindFromRequest();
为此我使用 playframeworks 形式 class。
您需要在登录时遵循 javabean 规范 class。您可以保留 Login public 的客户成员,但您必须将其包装在 getter/setter:
public Customer getCustomer() {
return this.customer();
}
public void setCustomer(Customer c) {
this.customer = c;
}
你说 play 应该在编译时为你生成那些 getters/setters,但似乎不是。我的理解是,它只对 entity/model classes 执行此操作,而且我在登录时没有看到 JPA @Entity 注释。同样让登录成为静态 class 对我来说似乎很奇怪。