-1
我正在做豆子的第一步,我想给学生一个宿舍,这也是一个班。我究竟做错了什么?我如何将类设置为bean中的值?
public class Student {
private String name;
private String id;
private Hostel hostel;
//getters and setters under this
public class Hostel {
private String hostelName;
private String city;
//also getters and setters
beanpart
<bean id="student" class="com.tom.demo.Student" autowire="byName">
<property name="name" value="Sönke Huster"></property>
<property name="id" value="s81862322B"></property>
</bean>
<bean id="student1" class="com.tom.demo.Student">
<property name="name" value="Thomas Bruhn"></property>
<property name="id" value="s8232322"></property>
<property name="hostel" value="aushos"/>
</bean>
<bean id="hostel" class="com.tom.demo.Hostel">
<property name="hostelName" value ="Bangladore East Hostel"></property>
<property name="city" value="Bangladore"></property>
</bean>
<bean id="aushos" class="com.tom.demo.Hostel">
<property name="hostelName" value ="Easy Go Backpackers"></property>
<property name="city" value="Sydney"></property>
</bean>
我的结果是:
Failed to convert property value of type `java.lang.String` to required type `com.tom.demo.Hostel` for property `hostel`; nested exception is `java.lang.IllegalStateException`
我已经尝试过谷歌或与铸造修复它,但我的知识是有限的。所以请帮助我。
我想你必须使用'ref = ....'引用其他bean。 –
很好,谢谢 –