Jim
Jim

Reputation: 29

Spring 2.5 to 3.2 upgrade error: Invalid property 'commandClass' of bean class

I am new to Spring and am upgrading a Spring 2.5 web app to 3.2.3. I am getting an error navigating off the front page of the app. The error is Invalid property 'commandClass' of bean class. This web app has been running for about 5 years, so the issue has to be the Spring 2.5 to 3.2 changes. I must have something wired wrong, any ideas?

The full error is :

    Error creating bean with name '/new_candidate.html' defined in ServletContext resource [/WEB-INF/webapp-servlet.xml]:

Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'commandClass' of bean class [org.myorg.app.web.ScoreChangeController]: Bean property 'commandClass' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

Here is the bean def from the webapp-sevlet.xml:

<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>

The controller is:

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

}

}

Upvotes: 0

Views: 1660

Answers (1)

saurav
saurav

Reputation: 3462

You are trying to inject property commandClass inside the ScoreChangeController bean, but i am not able to see any property with that name in that controller and moreover it is not a subclass of any specific controller also so no chance of inheritance also.

Solution : Either remove the injection of commandClassproperty from the ScoreChangeController bean .

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

OR create a new property in your ScoreChangeController having the name as command and create the setters and getters for that.

Upvotes: 1

Related Questions