<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=stolsvik" rel="nofollow">Endre Stølsvik</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-2801?redirect=false" rel="nofollow">SPR-2801</a></strong> and commented</p>
<p dir="auto">This request is similar to bug #<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398057408" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/5727" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/5727/hovercard" href="https://github.com/spring-projects/spring-framework/issues/5727">#5727</a>, "support "add"-style List injection", but suggests a more radical solution: Actual support for it in the spring beans xml-files: add-methods should be IoC-able in the same way as set-methods (and preferrably a mechanism to invoke any other method too, with any parameters).</p>
<p dir="auto">As posted in:<br>
<a href="http://forum.springframework.org/showthread.php?t=31058" rel="nofollow">http://forum.springframework.org/showthread.php?t=31058</a></p>
<p dir="auto">quoting:<br>
" Several types of "legacy beans" have "adder" methods for some properties instead of "setter" methods. This doesn't disqualify them from being handled as beans, I feel, but I can't figure out how I may invoke such a method in the same way as a property-setter? I have to be able to invoke such a method several times, obviously.. "</p>
<p dir="auto">" I'd like to do this in spring's xml config, preferrably w/o a lot of hacks: I've come to understand that the org.springframework.beans.factory.config.MethodInvokingFactoryBean is the most cited approach to this problem, which I find on the edge of ridiculous.<br>
I have this problem now with ActiveMQ, and I've had this problem with Jetty. Both have "addSomething": addConnector and addListener. "</p>
<p dir="auto">" Jetty have its own style of "IoC" when it comes to configuration: in this file one may "code in XML" using &lt;Call name="addListener"&gt; and &lt;New class=".."&gt; (in addition to &lt;Set name="..."&gt;). I know this isn't as clean as Spring, but at least one may get things done both with legacy and proper "IoC style" beans then.. "</p>
<p dir="auto">Add elements to the bean element, something along the lines of:</p>
<p dir="auto">&lt;bean id="broker"<br>
class="demo"<br>
init-method="start"<br>
destroy-method="stop"&gt;<br>
&lt;constructor-arg&gt;<br>
[ You know the deal ]<br>
&lt;/constructor-arg&gt;<br>
&lt;property name="setter"&gt;<br>
[ You know the deal ]<br>
&lt;/property&gt;<br>
&lt;add-property name="adder"&gt;<br>
[ Same semantics as  ]<br>
&lt;/add-property&gt;  [ multiple invocations to the same name must be allowed ]<br>
&lt;invoke name="someOtherMethod"&gt;<br>
&lt;argument&gt;<br>
[ Same semantics as  ]<br>
&lt;/argument&gt;  [ multiple invocations to the same name must be allowed ]<br>
&lt;/invoke&gt;<br>
&lt;/bean&gt;</p>
<p dir="auto">There are hacks to overcome this, read the referred thread (using org.springframework.beans.factory.config.MethodInvokingFactoryBean w/o really using it!), but this is obviously a thing that comes up from time to time in the forums, and it would be great if such style of configuration was supported natively. (btw: At least jetty could possibly use spring instead of its own config parsing then!).</p>
<hr>
<p dir="auto"><strong>Affects:</strong> 2.0 final</p>
<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="398050219" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/4961" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/4961/hovercard" href="https://github.com/spring-projects/spring-framework/issues/4961">#4961</a> Please improve BeanFactory support for containers &amp; collections (<em><strong>"duplicates"</strong></em>)</li>
</ul>
<p dir="auto">3 votes, 2 watchers</p>
<p dir="auto"><strong><a href="https://jira.spring.io/secure/ViewProfile.jspa?name=ben_hutchison" rel="nofollow">Ben Hutchison</a></strong> opened <strong><a href="https://jira.spring.io/browse/SPR-230?redirect=false" rel="nofollow">SPR-230</a></strong>* and commented</p>
<p dir="auto">Objects that contain other objects (common examples include Swing Containers and the Collections classes) frequently cannot have their initial state specified through setting javabeans properties alone.</p>
<p dir="auto">This is a request for the spring core to include extensions to the syntax of the applicationContext.xml to allow such objects to be setup completely from XML. Some reasonably conveinient syntax is needed that allows methods like "add()" to be invoked on the bean at construction time. Ideally, I think the syntax should allow any arbritrary methods to be called on a bean during preparation.</p>
<p dir="auto">There is a clear precendent to be found in the design of the java.beans.XMLEncoder/Decoder classes, designed to support long term bean perisstence. Consider the extract below generated by XML-serializing a List:</p>
<p dir="auto">&lt;?xml version="1.0" encoding="UTF-8" ?&gt;<br>
&lt;java version="1.4.2_03" class="java.beans.XMLDecoder"&gt;<br>
&lt;object class="java.util.ArrayList"&gt;<br>
&lt;void method="add"&gt;<br>
&lt;string&gt;item&lt;/string&gt;<br>
&lt;/void&gt;<br>
&lt;/object&gt;<br>
&lt;/java&gt;</p>
<p dir="auto">Evidently, it was recognized as an important feature as its present from the first release of the peristence mechanism.</p>
<p dir="auto">Consider what is <strong>not</strong> readily doable from XML without this feature:</p>
<ul dir="auto">
<li>Cannot create any Swing component heirarchies.</li>
<li>Cannot initialize custom collections (ie anything not a vanilla set/map/list impl), unless it provides a copy-constructor.</li>
<li>Cannot init arbritrary state on objects which do not observe the get/setXXX convention (and legacy code is littered with them).</li>
</ul>
<hr>
<p dir="auto"><strong>Affects:</strong> 1.0.2</p>
<p dir="auto"><strong>Attachments:</strong></p>
<ul dir="auto">
<li><a href="https://jira.spring.io/secure/attachment/15243/SPR-230.patch" rel="nofollow">SPR-230.patch</a> (<em>137.30 kB</em>)</li>
</ul>
<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="398070077" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7195" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7195/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7195">#7195</a> Allow setting of properties without a javabean setter (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398070258" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7222" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7222/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7222">#7222</a> Support JavaBean Eventing methods in Spring (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398072522" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/7488" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/7488/hovercard" href="https://github.com/spring-projects/spring-framework/issues/7488">#7488</a> "adder" injection in addition to "setter" (invoke addXX() instead of setXX()) (<em><strong>"is duplicated by"</strong></em>)</li>
<li><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="398057408" data-permission-text="Title is private" data-url="https://github.com/spring-projects/spring-framework/issues/5727" data-hovercard-type="issue" data-hovercard-url="/spring-projects/spring-framework/issues/5727/hovercard" href="https://github.com/spring-projects/spring-framework/issues/5727">#5727</a> support "add"-style List injection (<em><strong>"is duplicated by"</strong></em>)</li>
</ul>
<p dir="auto">32 votes, 28 watchers</p>