From c1d2c36f32291294407baebd7625955f02378f0b Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Wed, 15 Sep 2010 08:13:12 +0000 Subject: [PATCH] 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. --- .../src/beans-dependencies.xml | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/spring-framework-reference/src/beans-dependencies.xml b/spring-framework-reference/src/beans-dependencies.xml index f3cd4ba597..9156f077c9 100644 --- a/spring-framework-reference/src/beans-dependencies.xml +++ b/spring-framework-reference/src/beans-dependencies.xml @@ -170,9 +170,27 @@ public class ExampleBean { <constructor-arg name="ultimateanswer" value="42"/> </bean> - Keep in mind that your code has to be compiled with the debug - flag enabled so that Spring can lookup the parameter name from the - constructor. + Keep in mind that to make this work out of the box your code + has to be compiled with the debug flag enabled so that Spring can + lookup the parameter name from the constructor. If you can't compile + your code with debug flag (or don't want to) you can use + @ConstructorProperties + JDK annotation to explicitly name your constructor arguments. The + sample class would then have to look as follows: + + package examples; + +public class ExampleBean { + + // Fields omitted + + @ConstructorProperties({"years", "ultimateAnswer"}) + public ExampleBean(int years, String ultimateAnswer) { + this.years = years; + this.ultimateAnswer = ultimateAnswer; + } +}