Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"adder" injection in addition to "setter" (invoke addXX() instead of setXX()) [SPR-2801] #7488

Closed
spring-projects-issues opened this issue Nov 4, 2006 · 5 comments
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue type: enhancement A general enhancement

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Nov 4, 2006

Endre Stølsvik opened SPR-2801 and commented

This request is similar to bug ##5727, "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).

As posted in:
http://forum.springframework.org/showthread.php?t=31058

quoting:
" 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.. "

" 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.
I have this problem now with ActiveMQ, and I've had this problem with Jetty. Both have "addSomething": addConnector and addListener. "

" Jetty have its own style of "IoC" when it comes to configuration: in this file one may "code in XML" using <Call name="addListener"> and <New class=".."> (in addition to <Set name="...">). 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.. "

Add elements to the bean element, something along the lines of:

<bean id="broker"
class="demo"
init-method="start"
destroy-method="stop">
<constructor-arg>
[ You know the deal ]
</constructor-arg>
<property name="setter">
[ You know the deal ]
</property>
<add-property name="adder">
[ Same semantics as ]
</add-property> [ multiple invocations to the same name must be allowed ]
<invoke name="someOtherMethod">
<argument>
[ Same semantics as ]
</argument> [ multiple invocations to the same name must be allowed ]
</invoke>
</bean>

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!).


Affects: 2.0 final

Issue Links:

3 votes, 2 watchers

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 4, 2006

Endre Stølsvik commented

Similar to improvement request #7222, which asks for "adder injection" based on the requirement of registering event listeners, which often are registered/injected in beans using addListener methods.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 4, 2006

Endre Stølsvik commented

Also similar to improvement request #5727, which points out "Some classes don't expose a plublic setter for internal list (as an example, commons-configuration CompositeConfiguration) bue some addXXX(item) method."

@spring-projects-issues
Copy link
Collaborator Author

Christopher Sahnwaldt commented

Maybe we don't need a new element like <add-property>, just a new attribute...
Something like this?

<bean id="eventBean">
<property name="X" ref="listener1" action="add"/>
<property name="X" ref="listener2" action="add"/>
</bean>

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Nov 9, 2006

Christopher Sahnwaldt commented

I just found #4961 which explains it all. This issue is basically a duplicate of #4961 .

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Dec 17, 2006

Dave Syer commented

Marked as duplicate of #4961

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: core Issues in core modules (aop, beans, core, context, expression) status: duplicate A duplicate of another issue type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant