0
      <?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. これは、ID と従業員の依存関係を注入する別の依存関係 Bean クラスです。

        <bean id="employee" class="com.spring.collections"


            <property name="id" value="2312" />
            <property name="employeeName" value="SpringHero" />
        </bean>
    </beans>
4

1 に答える 1

3

コンテンツ (他の要素またはテキスト) をネストする前に、要素の開始タグを終了する必要があります。XML では、これで問題ありません。

<x>
  <y />
</x>

しかし、これはそうではありません:

<x
  <y />
</x>

これは Spring 固有でも Java 固有でもありません。現時点では単純な無効な XML を取得しています。開始タグ内に入れることができるのは属性だけです。

于 2014-09-10T02:54:39.027 に答える