0

Grails 有用于 spring bean 的 cofig,称为resources.groovy. 正如我从文档中了解的那样,它允许您使用 loadBeans(%path%) 包含另一个文件

我试过这个:

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/spring并由grails maven 插件编译成target/classes/security.class. 此时目录target/resources/spring为空

我如何配置 Grails 或 grails-maven-plugin 以复制此配置文件,而不是将其编译成类?

ps 当我尝试使用grails.config.locations = [ %path% ]inside包含配置脚本时,也会出现这个问题conf/Config.groovy,我的 groovy 脚本编译成类,因此,grails config builder 找不到它们:(

4

1 回答 1

1

你试过了吗:

println 'loading application config ...'


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

}

(这应该加载类路径上的所有 Groovy 文件,security.groovy并将它们解析为 bean 定义)。

更新:发现了一个有趣的线程这个消息作为参考,我的理解是一个技巧是使用 ant inscripts/_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 时让事情正常工作的黑客。不确定事情“应该”如何完成(如果这甚至有意义的话)。

于 2010-02-16T22:31:45.430 回答