You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LookupOverride only works for methods with no arguments [SPR-3017] #7703
in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement
Actually it used to work before 2.0, but now there is an explicit check in LookupOverride.matches. I can see why it is there sort of, but if there are no overloaded methods and only one matches and it happens to have some arguments, why shouldn't it match?
A workaround is to use a MethodOverride instead of a LookupOverride - you just have to implement the MethodReplacer to return the bean that you want. E.g.
I would argue that lookup-methods are not intended to have arguments in the first place: What's the point in accepting/passing in an argument and then ignoring it, performing a straight lookup for a specific bean by name? If we supported that, we'd need to do something with the arguments...
The present 2.0 implementation is clear and intuitive, I think, and allows for seamless adding of overloaded variants of the lookup method which may be implemented in a traditional fashion - without suddenly making the lookup-method tag fail or behave differently.
Furthermore, note that the documentation already indicated a no-arg requirement for lookup methods. It was just that the implementation didn't enforce that, assuming that there would be only only a single, non-overloaded no-arg method in the first place.
As for the MethodReplacer solution: A MethodReplacer is a generic callback which allows for full access to the arguments, so if a MethodReplacer implementation decides to ignore those, then that's its decision. The "lookup-method" support is simply more 'special purpose' in that respect, implying a no-arg method.
in: coreIssues in core modules (aop, beans, core, context, expression)status: declinedA suggestion or change that we don't feel we should currently applytype: enhancementA general enhancement
Activity
spring-projects-issues commentedon Jan 7, 2007
Dave Syer commented
A workaround is to use a MethodOverride instead of a LookupOverride - you just have to implement the MethodReplacer to return the bean that you want. E.g.
<bean id="bean" class="test.TestBean">
<replaced-method name="getFoo" replacer="replacer"/>
</bean>
<bean id="replacer" class="test.TestReplacer>
<property name="bean" ref="replaced"/>
</bean>
<bean id="replaced" class="test.Foo"/>
spring-projects-issues commentedon Jan 25, 2007
Juergen Hoeller commented
I would argue that lookup-methods are not intended to have arguments in the first place: What's the point in accepting/passing in an argument and then ignoring it, performing a straight lookup for a specific bean by name? If we supported that, we'd need to do something with the arguments...
The present 2.0 implementation is clear and intuitive, I think, and allows for seamless adding of overloaded variants of the lookup method which may be implemented in a traditional fashion - without suddenly making the lookup-method tag fail or behave differently.
Furthermore, note that the documentation already indicated a no-arg requirement for lookup methods. It was just that the implementation didn't enforce that, assuming that there would be only only a single, non-overloaded no-arg method in the first place.
As for the MethodReplacer solution: A MethodReplacer is a generic callback which allows for full access to the arguments, so if a MethodReplacer implementation decides to ignore those, then that's its decision. The "lookup-method" support is simply more 'special purpose' in that respect, implying a no-arg method.
Juergen