我是 Spring 新手,正在将 Spring 2.5 Web 应用程序升级到 3.2.3。我在离开应用程序的首页时遇到错误。错误是 bean 类的无效属性“commandClass”。这个 web 应用程序已经运行了大约 5 年,所以问题必须是 Spring 2.5 到 3.2 的变化。我一定是接线有问题,有什么想法吗?
完整的错误是:
Error creating bean with name '/new_candidate.html' defined in ServletContext resource [/WEB-INF/webapp-servlet.xml]:
设置属性值时出错;嵌套异常是 org.springframework.beans.NotWritablePropertyException:bean 类 [org.myorg.app.web.ScoreChangeController] 的无效属性“commandClass”:bean 属性“commandClass”不可写或具有无效的 setter 方法。setter 的参数类型是否与 getter 的返回类型匹配?
这是来自 webapp-sevlet.xml 的 bean def:
<bean name="/new_candidate.html" class="org.myorg.app.web.ScoreChangeController" scope="session">
<property name="commandClass" value="org.myorg.app.model.Database"/>
<property name="formView" value="generic"/>
<property name="candidateManager" ref="candidateManager"/>
</bean>
控制器是:
package org.myorg.app.web;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.myorg.app.model.Database;
import org.myorg.app.service.CandidateManager;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.view.RedirectView;
import org.springframework.web.bind.ServletRequestDataBinder;
import org.springframework.validation.BindException;
import org.springframework.web.util.WebUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
public class ScoreChangeController
{
private CandidateManager candidateManager;
protected Object formBackingObject(HttpServletRequest request) throws Exception {
Database defaultDatabase = new Database();
defaultDatabase.setApptNo("16 digits");
defaultDatabase.setAccessionNo("8 digits");
defaultDatabase.setTstPkgId("12345678912345678912345");
return defaultDatabase;
}
protected void initBinder(HttpServletRequest request, ServletRequestDataBinder binder) throws Exception {
Database database = (Database)binder.getTarget();
}
public CandidateManager getCandidateManager() {
return candidateManager;
}
public void setCandidateManager(CandidateManager candidateManager) {
this.candidateManager = candidateManager;
}
public ModelAndView onSubmit(HttpServletRequest req, HttpServletResponse res, Object command, BindException errors) throws Exception {
if(WebUtils.hasSubmitParameter(req, "retrieve"))
{
candidateManager.retrieveData((Database)command);
}
return new ModelAndView(new RedirectView("success.jsp"));
}
}