2012-04-28 95 views
3

从文档:是否可以在Spring中使用参数注入方法?

在包含该方法的客户端类被注入(在命令管理在这种情况下),即是“注入”必须具有以下形式的签名的方法:

<public|protected> [abstract] <return-type> theMethodName(no-arguments); 

是否存在解决此限制的方法?

+0

你想让Spring用这个方法的参数做什么? – 2012-04-28 17:08:00

+0

尝试[this](http://forum.springsource.org/showthread.php?32785-Lookup-method-injection-with-parameters)。这是旧的,但包含有用的指针。 – 2012-04-28 17:09:16

+0

检查选择的答案在这里http://stackoverflow.com/questions/5349362/spring-bean-initialization-with-multiple-arg-method 它为我工作。 – Deeps 2016-04-12 18:26:54

回答

2

是的,你可以。这里是一个来自春季文档的例子,http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/beans.html

@Autowired 
public void prepare(MovieCatalog movieCatalog, 
        CustomerPreferenceDao customerPreferenceDao) { 
    this.movieCatalog = movieCatalog; 
    this.customerPreferenceDao = customerPreferenceDao; 
} 
+0

是不是在询问查询方法?这实际上是通过代理注入的方法,而不是注入其参数的方法。 – 2012-04-28 17:07:36

+0

嗯,这个问题有点难以理解。我以为我有它的意义......但是读你的评论并重新阅读这个问题,听起来你可能是对的。 – 2012-04-28 17:19:00

相关问题