Error creating bean with name ***** Invalid property **** is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?

This is one of common error we see, that come across while working with Springs. The interdependency of beans on each other is so much nested, that we often miss to inject them properly. And that’s where such error comes.

For example, suppose i have a bean definition like this one,

<bean id=”removeSentEmail”
class=”de.hybris.platform.acceleratorservices.process.email.actions.RemoveSentEmailAction”
parent=”abstractAction”>
<property name=”modelService” ref=”modelService”/>
</bean>

Here, class RemoveSentEmailAction needs two services class to fulfill it’s purpose. They are injected using property reference and setter injection methods. So it is mandatory to have public setter methods in the class, which allows to set values of respective types. Like below

Class RemoveSentEmailAction {

……

private ModelService modelService;

public void setModelService(ModelService modelService){

this.modelService = modelService;

}

…….

}

Here, the thing to note is that, name of the property injected must be same as the member variable of class. Now Spring can easily set the dependency during spring server start up.