java – 元素类型“property”的内容必须匹配
发布时间:2020-12-15 02:13:40 所属栏目:Java 来源:网络整理
导读:?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="bean.Trinangle" property name="points" list ref bean="point1"/
<?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="bean.Trinangle"> <property name="points"> <list> <ref bean="point1"/> <ref bean="point2"/> <ref bean="point3"/> </list> </property> </bean> <bean id= "point1" class="bean.Point"> <property name="x" value="10"/> <property name="y" value="20"/> </bean> <bean id= "point2" class="bean.Point"> <property name="x" value="10"/> <property name="y" value="20"/> </bean> <bean id= "point3" class="bean.Point"> <property name="x" value="10"/> <property name="y" value="20"/> </bean> </beans> 题: 解决方法
我认为你实际上并没有创建一个List(如果setPoints预期的话).尝试这样的事情(取自
How to define a List bean in Spring?):
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:util="http://www.springframework.org/schema/util" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd"> <beans> <bean id= "point1" class="bean.Point"> <property name="x" value="10"/> <property name="y" value="20"/> </bean> <bean id= "point2" class="bean.Point"> <property name="x" value="10"/> <property name="y" value="20"/> </bean> <bean id= "point3" class="bean.Point"> <property name="x" value="10"/> <property name="y" value="20"/> </bean> <util:list id="pointList" value-type="bean.Point"> <value>point1</value> <value>point2</value> <value>point3</value> </util:list> <bean id="triangle" class="bean.Trinangle"> <property name="points" value="pointList" /> </bean> <bean id= "point1" class="bean.Point"> <property name="x" value="10"/> <property name="y" value="20"/> </bean> <bean id= "point2" class="bean.Point"> <property name="x" value="10"/> <property name="y" value="20"/> </bean> <bean id= "point3" class="bean.Point"> <property name="x" value="10"/> <property name="y" value="20"/> </bean> </beans> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |