org.springframework.beans.NullValueInNestedPathExceptio

在提交表单数据时出错,以下是出错信息。

org.springframework.beans.NullValueInNestedPathException: Invalid property 'address' of bean class [com.springmvc.bean.User]: Could not instantiate property type [com.springmvc.bean.Address] to auto-grow nested property path: java.lang.InstantiationException: com.atguigu.springmvc.bean.Addressat org.springframework.beans.BeanWrapperImpl.newValue(BeanWrapperImpl.java:649)at org.springframework.beans.BeanWrapperImpl.createDefaultPropertyValue(BeanWrapperImpl.java:618)at org.springframework.beans.BeanWrapperImpl.setDefaultValue(BeanWrapperImpl.java:607)at org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.java:572)at org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:546)at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:908)at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:82)at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:728)at org.springframework.validation.DataBinder.doBind(DataBinder.java:624)at org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:189)at org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:106)at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter$ServletHandlerMethodInvoker.doBind(AnnotationMethodHandlerAdapter.java:805)at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.doBind(HandlerMethodInvoker.java:813)at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:366)at org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:170)at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.invokeHandlerMethod(AnnotationMethodHandlerAdapter.java:446)at org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter.handle(AnnotationMethodHandlerAdapter.java:434)at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:931)at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:833)at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)

首先说明Address类是在User类中存在的,User类不报错,而Address报错了。


根据字面意思是:
无法实例化属性类型[com.springmvc.bean]。用于自动增长嵌套属性。

无法实例化?构造方法有问题?
然后我去查看了一下与之关联的User类,看到我在User类没有添加全参构造方法,而在Address类添加了,,,
然后我把构造方法去掉结果就好了。

public class Address {private String province;private String city;public String getProvince() {return province;}public void setProvince(String province) {this.province = province;}public String getCity() {return city;}public void setCity(String city) {this.city = city;}@Overridepublic String toString() {return "Address [province=" + province + ", city=" + city + "]";}}

所以总结的通用办法:

1)添加一个无参构造方法。
2)删除所有的构造方法。

本文链接:https://my.lmcjl.com/post/19363.html

展开阅读全文

4 评论

留下您的评论.