Skip to content

LookupOverride only works for methods with no arguments [SPR-3017] #7703

Closed

Description

@spring-projects-issues

Dave Syer opened SPR-3017 and commented

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?


Affects: 2.0.1

1 votes, 0 watchers

Activity

  1. spring-projects-issues commented on Jan 7, 2007

    @spring-projects-issues
    CollaboratorAuthor

    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"/>

  2. spring-projects-issues commented on Jan 25, 2007

    @spring-projects-issues
    CollaboratorAuthor

    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

  3. added
    status: declined
    type: enhancement
    in: core
    on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: corestatus: declinedtype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions