<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=benrowlands" rel="nofollow">Ben Rowlands</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-3313?redirect=false" rel="nofollow">SPR-3313</a></strong> and commented</p>
<p dir="auto">Constructor injection is desirable for imutability but the Spring config is very much tied to implementation (ordering of args).</p>
<p dir="auto">We could solve this problem using a <code class="notranslate">@Property</code>("..") 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).</p>
<p dir="auto">For example:</p>
<p dir="auto">public class Person<br>
{<br>
public Person( <code class="notranslate">@Property</code>("age") int age, <code class="notranslate">@Property</code>("name") String name )<br>
{<br>
...<br>
}<br>
}</p>
<p dir="auto">Then the config could look same as the if we had used setter injection.</p>
<p dir="auto">&lt;bean class="Person"&gt;<br>
&lt;property name="age" value=".."/&gt;<br>
&lt;property name="name" value=".."/&gt;<br>
&lt;/bean&gt;</p>
<p dir="auto">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?</p>
<p dir="auto">Alternativly we could add an attribute to constructor-arg</p>
<p dir="auto">&lt;bean class="Person"&gt;<br>
&lt;constructor-arg name="age" value=".."/&gt;<br>
&lt;constructor-arg name="name" value=".."/&gt;<br>
&lt;/bean&gt;</p>
<hr>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398064973" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/6580" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/6580/hovercard" href="https://github.com/spring-projects/spring-framework/issues/6580">#6580</a> Attach tooling metadata to constructor arg definitions (<em><strong>"depends on"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398066609" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/6769" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/6769/hovercard" href="https://github.com/spring-projects/spring-framework/issues/6769">#6769</a> Attach Source Metadata to Constructor Args</li>
</ul>
<p dir="auto"><strong>Referenced from:</strong> commits <a class="commit-link" data-hovercard-type="commit" data-hovercard-url="https://github.com/spring-projects/spring-framework/commit/53333c3ed06e465a55592a0f351ffab40110e5b3/hovercard" href="https://github.com/spring-projects/spring-framework/commit/53333c3ed06e465a55592a0f351ffab40110e5b3"><tt>53333c3</tt></a></p>
<p dir="auto">1 votes, 7 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=robh" rel="nofollow">Rob Harrop</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-2077?redirect=false" rel="nofollow">SPR-2077</a></strong> and commented</p>
<hr>
<p dir="auto"><strong>Issue Links:</strong></p>
<ul dir="auto">
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398076627" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7998" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7998/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7998">#7998</a> Add <code class="notranslate">@annotation</code> to name constructor arguments allowing names to be placed in config</li>
</ul>