Skip to content

Passing lookup-method args to bean constructor - #84

Closed
nurkiewicz wants to merge 1 commit into
spring-projects:mainfrom
nurkiewicz:SPR-7431
Closed

nurkiewicz wants to merge 1 commit into
spring-projects:mainfrom
nurkiewicz:SPR-7431

Conversation

@nurkiewicz

Copy link
Copy Markdown
Contributor

should allow specifying any number of parameters.
These parameters should be passed directly to the constructor of the
newly created bean.

Previously had to be parameterless. Now if you provide
any parameters to that method, they are passes directly (1 to 1) to the
bean constructor, just like if they were declared using
. The idea was originally suggested here:

http://nurkiewicz.blogspot.com/2010/08/creating-prototype-spring-beans-on.html

This change is based entirely on a patch provided by Karl Pietrzak.

I submitted CLA.

Issue: SPR-7431

<lookup-method/> should allow specifying any number of parameters.
These parameters should be passed directly to the constructor of the
newly created bean.

Previously <lookup-method/> had to be parameterless. Now if you provide
any parameters to that method, they are passes directly (1 to 1) to the
bean constructor, just like if they were declared using
<constructor-arg/>. The idea was originally suggested here:

http://nurkiewicz.blogspot.com/2010/08/creating-prototype-spring-beans-on.html

This change is based entirely on a patch provided by Karl Pietrzak.

Issue: SPR-7431
@ghost ghost assigned cbeams May 25, 2012
@cbeams

cbeams commented May 25, 2012

Copy link
Copy Markdown
Contributor

Thanks, Tomasz. Will take a look!

@nurkiewicz

Copy link
Copy Markdown
Contributor Author

Unfortunately my pull request causes testReplaceMethodOverrideWithSetterInjection() in org.springframework.beans.factory.xml.XmlBeanFactoryTests to fail. It's this assertion:

TestBean notJenny = oom.getPrototypeDependency("someParam");
assertTrue(!"Jenny".equals(notJenny.getName()));

it makes sure that overloaded getPrototypeDependency(String) method is not modified by Spring and only parameterless getPrototypeDependency() is overriden by lookup-method mechanism. This behavior changes after applying this patch. Now all methods, no matter if they have parameters or not, are overriden by lookup-method mechanism.

This means that lookup-method with parameters is not really backward compatible - in case there was more than one overloaded method. I am not sure how big this is. Applying lookup-method only if target bean has matching constructor (not always, what this pull request does) will help a little, but won't get rid of incompatibility completely.

My reviewed code is available at SPR-7431b branch.

rwinch pushed a commit to rwinch/spring-framework that referenced this pull request Jun 20, 2016
…stringdecoder

Use CharsetDecoder to decode a DataBuffer into a String.
rwinch pushed a commit to rwinch/spring-framework that referenced this pull request Jul 13, 2016
…stringdecoder

Use CharsetDecoder to decode a DataBuffer into a String.
@pivotal-issuemaster

Copy link
Copy Markdown

@nurkiewicz Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 24, 2019
@rstoyanchev rstoyanchev added the in: core Issues in core modules (aop, beans, core, context, expression) label Nov 12, 2021
@snicoll

snicoll commented Dec 3, 2021

Copy link
Copy Markdown
Member

@nurkiewicz sorry that this PR got overlooked. This is implemented in the meantime, and for quite a while already.

@snicoll snicoll closed this Dec 3, 2021
@snicoll snicoll added status: superseded An issue that has been superseded by another and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Dec 3, 2021
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: superseded An issue that has been superseded by another

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants