![](/img/trans.png)
[英]Spring DSL in Grails - resources.groovy - bean configuration in a different file?
[英]Is it possible to import an external bean configuration xml file into resources.groovy?
在我目前的grails應用程序中,我在resources.groovy中定義了spring bean。 現在我還有一個已經定義了一堆bean的xml文件,我想按原樣使用它們,而不是重新創建bean dsl中的每個bean。
這有可能嗎? grails bean dsl中是否有等效的xml導入標記? 我想在applicationContext.xml中添加import ...但是我不確定它是否適合這樣做。
提前致謝,
菲利普
您可以使用XML將XML文件中的bean導入resources.groovy
beans = {
importBeans('classpath:/applicationContext-services.xml')
}
您可以將其重命名為resources.xml
並將其放在同一文件夾中。 仍然支持xml版本,但它不會像Groovy版本那樣自動創建。
為了讓這個在grails 1.3.7上工作,我實際上必須做這樣的事情;
beans {
switch(Environment.current) {
case Environment.DEVELOPMENT:
importBeans('file:grails-app/conf/spring/messaging.xml')
break
default:
importBeans 'classpath*:WEB-INF/spring/messaging.xml'
break
}
}
我需要* after classpath,以便在應用程序服務器中運行時獲取它。 在開發中不起作用,因此它是不同的訪問者
有關匹配語法的文檔,請參閱http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/core/io/support/PathMatchingResourcePatternResolver.html 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.