有没有办法使用带有参数的 Spring 查找方法注入(inject)?例如,我希望能够实例化原型(prototype)范围的 bean,同时通过构造函数向它们传递任意参数。
请您参考如下方法:
看起来这个重要功能终于在 Spring 4.1.0.RC2 中添加了。我已经对其进行了测试,它似乎可以工作。
它是作为 JIRA 票证的一部分添加的 SPR-7431 ("Passing lookup-method arguments to created bean constructor") :
<lookup-method/> should allow specifying any number of parameters. These parameters should be passed directly to the constructor of the newly created bean.
有关如何最终添加该功能的更多信息, this blog post是开JIRA票的那个人写的。