在xml文件中为一个bean属性注入空值失败了

J2EE 码拜 8年前 (2016-03-19) 1598次浏览
下面是bean的Iclass源
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

Instrumentalist  类没有someNonNullProperty 属性

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明在xml文件中为一个bean属性注入空值失败了
喜欢 (1)
[1034331897@qq.com]
分享 (0)