2012-04-28 94 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

相關問題