[英]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
外,這還包括scope
, initMethod
和destroyMethod
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.