Issue Details (XML | Word | Printable)

Key: SPR-3313
Type: New Feature New Feature
Status: Open Open
Priority: Major Major
Assignee: Juergen Hoeller
Reporter: Ben Rowlands
Votes: 1
Watchers: 5
Operations

If you were logged in you would be able to see more operations.
Spring Framework

Add @annotation to name constructor arguments allowing names to be placed in config

Created: 28/Mar/07 09:33 AM   Updated: 20/Nov/08 04:12 PM
Component/s: SpringCORE
Affects Version/s: None
Fix Version/s: 3.0 M3

Time Tracking:
Not Specified

Issue Links:
Depends
 
Related
 


 Description  « Hide
Constructor injection is desirable for imutability but the Spring config is very much tied to implementation (ordering of args).

We could solve this problem using a @Property("..") annotation to decorate a constructor with the names of the ctor paramaters? (could locate param names from CGLIB but only if debug symbols stored in class).

For example:

public class Person
{
  public Person( @Property("age") int age, @Property("name") String name )
  {
     ...
  }
}

Then the config could look same as the if we had used setter injection.

<bean class="Person">
  <property name="age" value=".."/>
  <property name="name" value=".."/>
</bean>

This could be achieved using a BeanFactoryPostProcessor to visit every bean definition and move properties from the setter map to the constructor map respecting the order the annotations are definied in?

Alternativly we could add an attribute to constructor-arg

<bean class="Person">
  <constructor-arg name="age" value=".."/>
  <constructor-arg name="name" value=".."/>
</bean>

 All   Comments   Work Log   Change History   FishEye   Builds      Sort Order: Ascending order - Click to sort in descending order
Dave Syer added a comment - 29/Mar/07 08:30 AM
The constructor naming requirement is possibly related or duplicate of SPR-2077 (and SPR-1887?), but not enough detail there to tell.

Eugene Kuleshov added a comment - 29/Mar/07 11:22 AM
Please note that Java 6 has java.beans.ConstructorProperties annotation, which is used like this:

{code}
  public class Point {
    @ConstructorProperties({"x", "y"})
    public Point(int x, int y) {
      this.x = x;
      this.y = y;
    }
    ....
{code}