package com.springination.springidol;
import com.itextpdf.text.pdf.PdfStructTreeController.returnType;
public class Instrumentalist implements Performer {
private String song;
private Instrument instrument;
private int age;
/* public Instrumentalist(Instrument instrument) {
this.instrument = instrument;
} */
public void Perform() {
// TODO Auto-generated method stub
System.out.println(“Playing “+song+” : “+”\n”+”Age : “+age);
instrument.play();
}
public void setAge(int age) {
this.age = age;
}
public void setSong(String song){
this.song=song;
}
public String getSong(){
return song;
}
public String screamsong(){
return song;
}
public void setinstrument(Instrument instrument){
this.instrument=instrument;
}
public Instrument getinstrument(){
return this.instrument;
}
}
本人想为注入一个bean,某些属性设置为空值,例如为instrument这个属性设置为null,但是会报错
这是xml的bean
</bean>
<bean id=”carl”
class=”com.springination.springidol.Instrumentalist”>
<property name=”someNonNullProperty”><null/></property>
<property name=”song” value=”#{kenny.song}” />
<property name=”age” value=”#{22}” />
</bean>
Error creating bean with name “carl” defined in class path resource [spring-idol.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property “someNonNullProperty” of bean class [com.springination.springidol.Instrumentalist]: Bean property “someNonNullProperty” is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
20