0

我是 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"));

}

}
4

1 回答 1

1

您正在尝试commandClassScoreChangeControllerbean 中注入属性,但我无法在该控制器中看到具有该名称的任何属性,而且它也不是任何特定控制器的子类,因此也没有继承的机会。

解决方案:要么从bean中删除commandClass属性注入。ScoreChangeController

<bean name="/new_candidate.html" class="org.myorg.app.web.ScoreChangeController" scope="session">
<property name="formView" value="generic"/>
<property name="candidateManager" ref="candidateManager"/>

或者在您的 ScoreChangeController 中创建一个名为 command 的新属性,并为此创建 setter 和 getter。

于 2013-07-31T20:30:17.297 回答