簡體   English   中英

Spring 4 / Groovy DSL-自動裝配

[英]Spring 4 / Groovy DSL - autowiring

在Spring 4中使用Groovy DSL時如何啟用自動裝配?

如果我的config.groovy文件當前如下所示:

beans {
    mongoClient(com.mongodb.MongoClient)

    hello(org.abiri.HelloImpl) {
        mongoClient = mongoClient
    }
}

以前在XML配置中,我們可以這樣做:

<bean id="hello" class="org.abiri.HelloImpl" autowire="byType" />

我們甚至可以為整個文件啟用該功能:

<beans default-autowire="byType" />

什么是新的Groovy DSL中的那些XML代碼段等效,即,為了將mongoClient autowired到hello我需要做什么?

您需要使用

hello(org.abiri.HelloImpl) { bean ->
  bean.autowire = "byType"
}

配置閉包中傳遞了一個參數,您可以使用該參數來配置XML配置中bean元素上的屬性。 除了autowire外,這還包括scopeinitMethoddestroyMethod

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM