Spring MVC | Could not instantiate property type to auto-grow nested property path -


folks,

i'm using spring mvc (4.1.0.release) , have form want display user. here snippet thymeleaf view:

<form class="form-login" th:action="@{/admin/question/add}" th:object="${question}" method="post">     <div class="login-wrap">                         <input type="text" class="form-control" placeholder="question" th:field="*{questionstr}" autofocus>                         <br>                         <input type="text" class="form-control" placeholder="option one" th:field="*{answeroptions.optionone}" autofocus>                         <br>                         <input type="text" class="form-control" placeholder="option two" th:field="*{answeroptions.optiontwo}" autofocus>                         <br>                         <input type="text" class="form-control" placeholder="option three" th:field="*{answeroptions.optionthree}" autofocus>                         <br>                         <input type="text" class="form-control" placeholder="option four" th:field="*{answeroptions.optionfour}" autofocus>                         <br>                         <button class="btn btn-theme btn-block" type="submit"><i class="fa fa-lock"></i> submit</button>                         <hr>                     </div> 

i have exposed "question" form backing object.

    @autowired     private question question;      @requestmapping(value = "add", method = requestmethod.get)     public modelandview add(modelandview model) {         model.setviewname("admin/add/question");         model.addobject("question", question);         return model;     } 

question interface:

@component public interface question {      string getquestionstr();      void setquestionstr(string question);     ....     .... } 

question implementation:

@component public class questionimpl implements question {      private string questionstr;      private answer answeroptions;      private answer correctanswer;      private set<tagsimpl> tags;      ....     ....  } 

similarly, have answer interface , answerimpl.

now problem face when request page following exception:

org.springframework.beans.nullvalueinnestedpathexception: invalid property 'answeroptions' of bean class [com.xyz.abc.bean.impl.questionimpl]: not instantiate property type [com.saxena.vaibhav.bean.answer] auto-grow nested property path: java.lang.instantiationexception: com.xyz.abc.bean.answer 

i understand not able instantiate interfaces. changes replaced answer answerimpl in question.java , questionimpl.java. solved problem. not sound solution having concrete implementations in interfaces.

is there way can around error?

spring configuration:

@configuration @componentscan("com.xyz.abc") @enablewebmvc public class webconfig extends webmvcconfigureradapter {      /**      *       * @return servletcontexttemplateresolver servletcontexttemplateresolver.      */     @bean     @description("thymeleaf template resolver serving html 5")     public servletcontexttemplateresolver templateresolver() {         servletcontexttemplateresolver templateresolver = new servletcontexttemplateresolver();         templateresolver.setprefix("/web-inf/views/");         templateresolver.setsuffix(".html");         templateresolver.settemplatemode("legacyhtml5");         templateresolver.setcacheable(false);         return templateresolver;     }      @bean     @description("thymeleaf template engine spring integration")     public springtemplateengine templateengine() {         springtemplateengine templateengine = new springtemplateengine();         templateengine.settemplateresolver(templateresolver());         return templateengine;     }      @bean     @description("thymeleaf view resolver")     public thymeleafviewresolver thymeleafviewresolver(){         thymeleafviewresolver viewresolver = new thymeleafviewresolver();         viewresolver.settemplateengine(templateengine());         return viewresolver;     }      @override        public void addresourcehandlers(resourcehandlerregistry registry) {         registry.addresourcehandler("/resources/**").addresourcelocations("/resources/");     }      @bean(name = "hibernateproperties")     public propertiesfactorybean hibernateproperties() {          propertiesfactorybean bean = new propertiesfactorybean();         bean.setlocation(new classpathresource("properties/hibernate.props"));         return bean;     } 

answer.java

@component public interface answer {       string getoptionone();       void setoptionone(string optionone);       string getoptiontwo();       void setoptiontwo(string optiontwo);       string getoptionthree();       void setoptionthree(string optionthree);       string getoptionfour();       void setoptionfour(string optionfour); 


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -