File tree 1 file changed +21
-3
lines changed
spring-framework-reference/src
1 file changed +21
-3
lines changed Original file line number Diff line number Diff line change @@ -170,9 +170,27 @@ public class ExampleBean {
170
170
< constructor-arg name="ultimateanswer" value="42"/>
171
171
< /bean> </programlisting >
172
172
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 >
176
194
</section >
177
195
</section >
178
196
</section >
You can’t perform that action at this time.
0 commit comments