我收到以下错误:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'triangle' defined in class path resource [spring.xml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.lang.String' to required type 'com.mycompany.springdemo.Point' for property 'point0'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [java.lang.String] to required type [com.mycompany.springdemo.Point] for property 'point0': no matching editors or conversion strategy found
我的弹簧配置文件是:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN" "http://www.springframework.org/dtd/spring- beans-2.0.dtd">
<beans>
<bean id="triangle" class="com.mycompany.springdemo.Triangle">
<property name="point0">
<idref bean = "point01"/>
</property>
<property name="point1">
<bean class="com.mycompany.springdemo.Point">
<property name="x" value="20"/>
<property name="y" value="0"/>
</bean>
</property>
<property name="point2">
<bean class="com.mycompany.springdemo.Point">
<property name="x" value="0"/>
<property name="y" value="20"/>
</bean>
</property>
</bean>
<bean id="point01" class="com.mycompany.springdemo.Point">
<property name="x" value="0"/>
<property name="y" value="0"/>
</bean>
</beans>
如果我使用'ref'来初始化point0然后它工作正常,但是'idref'的错误。
答案 0 :(得分:0)
而不是:
<property name="point0">
<idref bean = "point01"/>
</property>
使用它:
<property name="point0" ref="point01" />