<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="SampleWorld" class="com.spring.collections"
1.这就是我得到元素类型“bean”必须后跟属性规范“">”或“/>”的要点。
<property name="list">
<list>
<value> 1 </value>
</list>
<ref = employee " />
</property>
<property name="set">
<set>
<value> 21</value>
</set>
<ref = employee " />
</property>
<property name="properties">
<properties>
<value> 21</value>
</properties>
<ref = employee " />
</property>
<property name="map">
<map>
<entry key="1" value="value1" />
<entry key="2" value-ref="employee" />
</map>
</property>
</bean>
2.这是另一个用于注入(inject) id 和员工依赖项的依赖项 bean 类。
<bean id="employee" class="com.spring.collections"
<property name="id" value="2312" />
<property name="employeeName" value="SpringHero" />
</bean>
</beans>
最佳答案
在拥有任何嵌套内容(其他元素或文本)之前,您必须先完成元素的开始标记。在 XML 中,这很好:
<x>
<y />
</x>
但这不是:
<x
<y />
</x>
这不是 Spring 特定的或 Java 特定的 - 目前您已经得到了简单的无效 XML。开始标记中唯一可以包含的内容是属性。
关于java - 为什么显示元素类型 "bean"后面必须跟有属性规范 ">"或 "/>".at <property name ="list">,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25756597/