【问题标题】:The content of the element type "property" must match元素类型“属性”的内容必须匹配
【发布时间】:2016-03-21 07:20:33
【问题描述】:
<?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>              

问题: 这是我的 XML 文件。在第 6 行我收到错误“元素类型“属性”的内容必须匹配“(描述?,元 *,(bean|ref|idref|value|null|list|set|map| 道具)?)“。”。

【问题讨论】:

标签: java xml spring


【解决方案1】:

我认为您实际上并没有创建一个列表(如果这是 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>

【讨论】:

    【解决方案2】:

    您的版本与 xml 版本不匹配,您必须尝试下面的 doctype 声明。

    <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 " default-lazy-init="true">
    

    【讨论】:

      猜你喜欢
      • 2017-03-22
      • 1970-01-01
      • 2012-09-10
      • 2015-06-26
      • 2017-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多