@@ -927,14 +927,14 @@ element.
927
927
[subs="verbatim,quotes"]
928
928
----
929
929
<beans>
930
- <bean id="thingOne " class="x.y.ThingOne">
931
- <constructor-arg ref="thingTwo "/>
932
- <constructor-arg ref="thingThree "/>
930
+ <bean id="beanOne " class="x.y.ThingOne">
931
+ <constructor-arg ref="beanTwo "/>
932
+ <constructor-arg ref="beanThree "/>
933
933
</bean>
934
934
935
- <bean id="thingTwo " class="x.y.ThingTwo"/>
935
+ <bean id="beanTwo " class="x.y.ThingTwo"/>
936
936
937
- <bean id="thingThree " class="x.y.ThingThree"/>
937
+ <bean id="beanThree " class="x.y.ThingThree"/>
938
938
</beans>
939
939
----
940
940
====
@@ -1937,27 +1937,28 @@ The following example uses the `c:` namespace to do the same thing as the from
1937
1937
xsi:schemaLocation="http://www.springframework.org/schema/beans
1938
1938
http://www.springframework.org/schema/beans/spring-beans.xsd">
1939
1939
1940
- <bean id="thingOne " class="x.y.ThingTwo"/>
1941
- <bean id="thingTwo " class="x.y.ThingThree"/>
1940
+ <bean id="beanTwo " class="x.y.ThingTwo"/>
1941
+ <bean id="beanThree " class="x.y.ThingThree"/>
1942
1942
1943
- <!-- traditional declaration -->
1944
- <bean id="thingOne " class="x.y.ThingOne">
1945
- <constructor-arg ref ="thingTwo"/>
1946
- <constructor-arg ref ="thingThree"/>
1947
- <constructor-arg value="[email protected] "/>
1943
+ <!-- traditional declaration with optional argument names -->
1944
+ <bean id="beanOne " class="x.y.ThingOne">
1945
+ <constructor-arg name ="thingTwo" ref="beanTwo "/>
1946
+ <constructor-arg name ="thingThree" ref="beanThree "/>
1947
+ <constructor-arg name="email" value="[email protected] "/>
1948
1948
</bean>
1949
1949
1950
- <!-- c-namespace declaration -->
1951
- <bean id="thingOne" class="x.y.ThingOne" c:thingTwo-ref="thingTwo" c:thingThree-ref="thingThree" c:email="[email protected] "/>
1950
+ <!-- c-namespace declaration with argument names -->
1951
+ <bean id="beanOne" class="x.y.ThingOne" c:thingTwo-ref="beanTwo"
1952
+ c:thingThree-ref="beanThree" c:email="[email protected] "/>
1952
1953
1953
1954
</beans>
1954
1955
----
1955
1956
====
1956
1957
1957
- The `c:` namespace uses the same conventions as the `p:` one (a trailing `-ref` for bean
1958
- references) for setting the constructor arguments by their names. Similarly, it
1959
- needs to be declared even though it is not defined in an XSD schema (it exists
1960
- inside the Spring core).
1958
+ The `c:` namespace uses the same conventions as the `p:` one (a trailing `-ref` for
1959
+ bean references) for setting the constructor arguments by their names. Similarly,
1960
+ it needs to be declared in the XML file even though it is not defined in an XSD schema
1961
+ (it exists inside the Spring core).
1961
1962
1962
1963
For the rare cases where the constructor argument names are not available (usually if
1963
1964
the bytecode was compiled without debugging information), you can use fallback to the
@@ -1968,12 +1969,15 @@ argument indexes, as follows:
1968
1969
[subs="verbatim,quotes"]
1969
1970
----
1970
1971
<!-- c-namespace index declaration -->
1971
- <bean id="thingOne" class="x.y.ThingOne" c:_0-ref="thingTwo" c:_1-ref="thingThree"/>
1972
+ <bean id="beanOne" class="x.y.ThingOne" c:_0-ref="beanTwo" c:_1-ref="beanThree"
1973
+
1972
1974
----
1973
1975
====
1974
1976
1975
1977
NOTE: Due to the XML grammar, the index notation requires the presence of the leading `_`,
1976
1978
as XML attribute names cannot start with a number (even though some IDEs allow it).
1979
+ A corresponding index notation is also available for `<constructor-arg>` elements but
1980
+ not commonly used since the plain order of declaration is usually sufficient there.
1977
1981
1978
1982
In practice, the constructor resolution
1979
1983
<<beans-factory-ctor-arguments-resolution,mechanism>> is quite efficient in matching
0 commit comments