lass org.springframework.beans.BeanWrapperImpl can not access a member of class org.test.User with m

下一篇:很抱歉没有了

在使用springmvc开发时代码中出现如下错误,解决方法如下

aused by: org.springframework.beans.InvalidPropertyException: Invalid property 'userList[0]' of bean class [org.test.User]: Illegal attempt to get property 'userList' threw exception; nested exception is org.springframework.beans.NullValueInNestedPathException: Invalid property 'userList' of bean class [org.test.User]: Could not instantiate property type [org.test.User] to auto-grow nested property path: java.lang.IllegalAccessException: Class org.springframework.beans.BeanWrapperImpl can not access a member of class org.test.User with modifiers "private"
    at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:827)
    at org.springframework.beans.BeanWrapperImpl.getNestedBeanWrapper(BeanWrapperImpl.java:554)
    at org.springframework.beans.BeanWrapperImpl.getBeanWrapperForPropertyPath(BeanWrapperImpl.java:531)
    at org.springframework.beans.BeanWrapperImpl.setPropertyValue(BeanWrapperImpl.java:892)
    at org.springframework.beans.AbstractPropertyAccessor.setPropertyValues(AbstractPropertyAccessor.java:75)
    at org.springframework.validation.DataBinder.applyPropertyValues(DataBinder.java:740)
    at org.springframework.validation.DataBinder.doBind(DataBinder.java:636)
    at org.springframework.web.bind.WebDataBinder.doBind(WebDataBinder.java:191)
    at org.springframework.web.bind.ServletRequestDataBinder.bind(ServletRequestDataBinder.java:112)
    at org.springframework.web.servlet.mvc.method.annotation.ServletModelAttributeMethodProcessor.bindRequestParameters(ServletModelAttributeMethodProcessor.java:153)
    at org.springframework.web.method.annotation.ModelAttributeMethodProcessor.resolveArgument(ModelAttributeMethodProcessor.java:106)
    at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:77)
    at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:123)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:745)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:686)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:925)
    ... 41 more
Caused by: org.springframework.beans.NullValueInNestedPathException: Invalid property 'userList' of bean class [org.test.User]: Could not instantiate property type [org.test.User] to auto-grow nested property path: java.lang.IllegalAccessException: Class org.springframework.beans.BeanWrapperImpl can not access a member of class org.test.User with modifiers "private"
    at org.springframework.beans.BeanWrapperImpl.newValue(BeanWrapperImpl.java:633)
    at org.springframework.beans.BeanWrapperImpl.growCollectionIfNecessary(BeanWrapperImpl.java:865)
    at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:770)
    ... 59 more

通过上述错误发现User这个类不允许被访问,查看了一下代码原来是自己把构造函数写成了private 导致不能解析

解决方法把私有的构造函数改成public 

原来private User() {} 修改成public User() {}

来源://作者:/更新时间:2018-07-13
相关文章
评论:
验证码:
匿名评论:

最新文章

文章排行