简体   繁体   中英

org.springframework.beans.NotReadablePropertyException: Invalid property. Bean property is not readable or has an invalid getter method

I struggle with this errors:

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)

I can't figure out when I did make code change, that causes this error. Few days ago it just worked.

Here is full stack trace:

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

Generally it is problem with binding data from serialized html form to java object of class Form<>

Here is my login 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;
        }
}

Here is my Customer 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;
    }
}

I don't paste form view class, cause this error occur while binding each form that contain customer class/parameter.

Here is binding code when the error occur:

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

I use playframeworks form class for this.

You need to follow the javabean specification with your Login class. You can leave the customer member of Login public, but you'll have to wrap it in a getter/setter:

public Customer getCustomer() {

 return this.customer();

}

public void setCustomer(Customer c) {

 this.customer = c;

}

You say play should be generating those getters/setters for you at compile time, but doesn't seem to be. My understanding is that It only does this only for entity/model classes and I don't see an JPA @Entity annotation on Login. Also having Login be a static class seems strange to me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM