【问题标题】:Is possible to inject method with arguments in Spring?是否可以在 Spring 中注入带有参数的方法?
【发布时间】:2012-05-09 01:59:24
【问题描述】:

来自文档:

在包含要注入的方法的客户端类(本例中为 CommandManager)中,要“注入”的方法必须具有以下形式的签名:

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

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

【问题讨论】:

标签: java spring methods arguments inject


【解决方案1】:

是的,你可以。这是 spring 文档中的一个示例,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;
 }

【讨论】:

  • OP 不是在询问查找方法吗?它实际上是通过代理注入的方法,而不是注入其参数的方法。
  • 嗯,这个问题有点难以理解。我以为我有它的意思......但是阅读您的评论并重新阅读问题,听起来您可能是正确的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-01-21
  • 1970-01-01
  • 2016-03-31
  • 1970-01-01
  • 1970-01-01
  • 2022-01-12
  • 1970-01-01
相关资源
最近更新 更多