Skip to content

Commit c1d2c36

Browse files
committed
SPR-7443 - Mentioned @ConstructorProperties in doc
If you want to reference parameters by name in XML configuration you can also use @ConstructorProperties to name the parameters in the class.
1 parent e8b9c6d commit c1d2c36

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

spring-framework-reference/src/beans-dependencies.xml

+21-3
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,27 @@ public class ExampleBean {
170170
<constructor-arg name="ultimateanswer" value="42"/>
171171
&lt;/bean&gt;</programlisting>
172172

173-
<para>Keep in mind that your code has to be compiled with the debug
174-
flag enabled so that Spring can lookup the parameter name from the
175-
constructor.</para>
173+
<para>Keep in mind that to make this work out of the box your code
174+
has to be compiled with the debug flag enabled so that Spring can
175+
lookup the parameter name from the constructor. If you can't compile
176+
your code with debug flag (or don't want to) you can use
177+
<interfacename><ulink
178+
url="http://download.oracle.com/javase/6/docs/api/java/beans/ConstructorProperties.html">@ConstructorProperties</ulink></interfacename>
179+
JDK annotation to explicitly name your constructor arguments. The
180+
sample class would then have to look as follows:</para>
181+
182+
<programlisting language="java">package examples;
183+
184+
public class ExampleBean {
185+
186+
<lineannotation>// </lineannotation>Fields omitted
187+
188+
@ConstructorProperties({"years", "ultimateAnswer"})
189+
public ExampleBean(int years, String ultimateAnswer) {
190+
this.years = years;
191+
this.ultimateAnswer = ultimateAnswer;
192+
}
193+
}</programlisting>
176194
</section>
177195
</section>
178196
</section>

0 commit comments

Comments
 (0)