NotReadablePropertyException:Bean类的无效属性'moduleName' [英] NotReadablePropertyException: Invalid property 'moduleName' of bean class

查看:117
本文介绍了NotReadablePropertyException:Bean类的无效属性'moduleName'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Spring MVC应用程序中遇到以下异常:

I am getting the following exception in Spring MVC application:

org.springframework.beans.NotReadablePropertyException: Invalid property 'moduleName' of bean class      [java.lang.String]: Bean property 'moduleName' is not readable or has an invalid getter method: Does the return type of the getter match the parameter type of the setter?
org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:726)
org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:717)
org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:149)

JSP代码

<form:form method="post" action="/submitSurvey" modelAttribute="surveyModule" > 
<form:label  path="moduleName">Module Name</form:label>
<form:input path="moduleName" />
<input type="submit" value="Save"/>
</form:form>

Spring Controller

Spring Controller

@RequestMapping(value = "/submitSurvey", method = RequestMethod.POST)
public String submitSurvey(@ModelAttribute("surveyModule")SurveyModule sm, Model model){
    surveyService.setSurveyModule(sm);
    return "surveyHome";
}

Bean:SurveyModule.java

Bean: SurveyModule.java

@Entity
@Table(name="SURVEYMODULE")
public class SurveyModule {

@Id
@Column(name="SurveyModuleId")
@GeneratedValue(strategy=GenerationType.IDENTITY)
private Integer surveyModuleId;
private String moduleName;

public Integer getSurveyModuleId() {
    return surveyModuleId;
}
public void setSurveyModuleId(Integer surveyModuleId) {
    this.surveyModuleId = surveyModuleId;
}
public String getModuleName() {
    return moduleName;
}
public void setModuleName(String moduleName) {
    this.moduleName = moduleName;
}
}

bean模块中存在属性moduleName.虽然我可以使用该属性来获取数据,但为什么会出现此错误?我该如何纠正?

The property moduleName exist in the bean class. While I am able to use the property to get data, why I am getting this error? How can I correct this?

推荐答案

请注意该错误提示

Invalid property 'moduleName' of bean class      [java.lang.String]

表示ElResolver将surveyModule解析为 String 而不是 SurveyModule 类.这意味着存在具有相同密钥的分配,这导致了您的问题.检查用于存储在其他模型属性或会话中的键,并检查页面中是否没有<c:set var="surveyModule"

which means that ElResolver resolves surveyModule as String and not as a SurveyModule class. That means that there is an assignment with the same key, that is causing your problem. Check the keys you use for storing in other model attributes or session, also check that there is no <c:set var="surveyModule" somewhere in your page

这篇关于NotReadablePropertyException:Bean类的无效属性'moduleName'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆