2010-02-16 73 views
0

Grails有一個名爲resources.groovy的spring bean的cofig。當我從文檔瞭解它允許你包含另一個文件,使用loadBeans(%路徑%)Spring beans在不同文件中的Grails配置

我試過這樣:

println 'loading application config ...' 


// Place your Spring DSL code here 
beans = { 
    loadBeans("classpath:security") //i'm tried with "spring/security" and "spring/security.groovy" also 

} 

但是當Grails是運行它記錄以下錯誤:

Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Error evaluating bean definition script: class path resource [security] cannot be opened because it does not exist 
Offending resource: class path resource [security]; nested exception is java.io.FileNotFoundException: class path resource [security] cannot be opened because it does not exist 
at grails.spring.BeanBuilder.loadBeans(BeanBuilder.java:470) 
at grails.spring.BeanBuilder.loadBeans(BeanBuilder.java:424) 
at resources$_run_closure1.doCall(resources.groovy:13) 
at resources$_run_closure1.doCall(resources.groovy) 
... 45 more 

腳本security.groovy是存在於grails-app/conf/springGrails的Maven插件編譯成target/classes/security.class。 目錄target/resources/spring目前爲空

如何配置Grails或grails-maven-plugin來複制此配置文件,而不是將它編譯成類?

p.s.這個問題也存在,當我嘗試使用grails.config.locations = [ %path% ]conf/Config.groovy包括配置腳本,我的Groovy腳本編譯成類和,因爲它是,Grails配置建設者無法找到他們:(

回答

1

你嘗試:

println 'loading application config ...' 


// Place your Spring DSL code here 
beans = { 
    loadBeans("classpath:*security.groovy") 

} 

(這應該載入所有Groovy文件與 security.groovy結束的類路徑,並將其解析爲bean定義)

更新日期:找到一個interesting threadthis message作爲參考,我的理解是,一個技巧是使用螞蟻在scripts/_Events.groovy.groovy文件複製到classesDirPath目錄,然後簡單地使用:

beans = { 
    // load spring-beans for db-access via spring-jdbc-template 
    loadBeans('security.groovy') 

    // load some other spring-beans 
     ... 
} 

這看起來像一個黑客得到的東西雖然在戰爭和運行run-app時都有工作。不知道如何做「應該」(如果這甚至是有意義的)。

+0

嘗試過,但沒有成功:(還有aro沒有任何security.groovy在classpath中的任何地方,grails編譯成security.class我認爲它是問題的根源,但不知道如何解決這個問題 – 2010-02-16 22:46:24

+0

謝謝,與_Event.groovy破解幫助我 – 2010-02-17 20:25:43

+1

這些鏈接已損壞:( – user2427 2010-11-15 16:15:01

相關問題