Hi, I have the following code in the application-context of my project.
bean id="bean" class="ej.tutorial.spring.model.MyBean" />
<bean id="beanSvc" class="ej.tutorial.spring.model.OtherBean">
<property name="mBean" ref="bean"/>
</bean>
The classes are the following:
public class MyBean {
private int valor;
private String msg;
public MyBean(){
}
public MyBean(int valor,String msg){
this.valor = valor;
this.msg = msg;
}
public int getValor() {
return valor;
}
public void setValor(int valor) {
this.valor = valor;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
OtherBean class:
public class OtherBean {
private MyBean mBean;
public OtherBean(){
}
public OtherBean(MyBean bean){
this.mBean = bean;
}
public MyBean getmBean() {
return mBean;
}
public void setmBean(MyBean mBean) {
this.mBean = mBean;
}
}
Well, the application-context gives me an error. The error is the following.
No setter found for property 'mBean' in class 'ej.tutorial.spring.model.OtherBean
The truth is that I can't find a logical explanation for it since the setter of the mBean attribute is defined in the OtherBean class.
In your
applicationContex.xml
define your bean and its property:For properties, the getters and setters are named like:
get/is/set
1 , followed byproperty name, with the first letter capitalized .
So, for the property
mBean
, you should define the methodsgetMBean()
andsetMBean(MBean mBean)
.1 In theory, if the property is of type
boolean
, the getter should start withis
instead ofget
, but I don't know of any framework that doesn't find the getter if you write it withget
.Note that if the property is
Boolean
, then it must be usedget
.