Spring bean在不同文件中的Grails配置 [英] Grails config of Spring beans in different files

查看:160
本文介绍了Spring bean在不同文件中的Grails配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



我试过这个:

  println'加载应用程序配置...'


//将您的Spring DSL代码放在这里
beans = {
loadBeans(classpath:security)//我用spring / security和spring / security.groovy来试用也是

}

但是当grails运行时,它会记录以下错误:

<$ p $导致:org.springframework.beans.factory.parsing.BeanDefinitionParsingException:配置问题:评估bean定义脚本时出错:class path resource [security]无法打开,因为它不存在
发布资源:类路径资源[安全];嵌套异常是java.io.FileNotFoundException:类路径资源[security]无法打开,因为它不存在
在grails.spring.BeanBuilder.loadBeans(BeanBuilder.java:470)
在grails.spring .BeanBuilder.loadBeans(BeanBuilder.java:424)
资源$ _run_closure1.doCall(resources.groovy:13)
资源$ _run_closure1.doCall(resources.groovy)
... 45 more

脚本 security.groovy is exists在 grails-app / conf / spring 并由 grails maven plugin 编译到 target / classes / security.class code>。
目录 target / resources / spring 目前为空


如何配置Grails或grails -maven-plugin复制这个配置文件,不编译成类?



ps当我尝试使用 grails.config.locations = [%path%] conf / Config.groovy中包含配置脚本时, code>,我的groovy脚本编译成类,正因为如此,grails config builder无法找到它们:($ / $>

解决方案


您尝试过:

  println'正在加载应用程序配置...'


//将您的Spring DSL代码放在这里
beans = {
loadBeans(classpath:* security.groovy)

}

(这应该加载类路径中以 security.groovy 并将它们解析为bean定义)



更新:找到有趣的帖子 with 此消息作为参考我的理解是,一个技巧是在 scripts / _Events.groovy 中使用ant将 .groovy 文件复制到 classesDirPath dir然后简单地使用:

  beans = {
//通过spring-jdbc-template为db-access加载spring-beans
loadBeans('security.groovy')

//加载其他spring-beans
...
}

这看起来像是一件骇人听闻的事情,并在运行run-app的时候。不知道如何做应该(如果这甚至是有意义的)。


Grails have cofig for spring bean called resources.groovy. And as i understand from docs it allows you to include another file, using loadBeans(%path%)

I'm tried with this:

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

}

but when grails is running it log following error:

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

Script security.groovy is exists at grails-app/conf/spring and compiled by grails maven plugin into target/classes/security.class. Directory target/resources/spring is empty at this time

How i can configure Grails or grails-maven-plugin to copy this config files, not compile it into classes?

p.s. this problem also presents when i try to include config scripts using grails.config.locations = [ %path% ] inside conf/Config.groovy, my groovy scripts compiles into classes and because of it, grails config builder can't find them :(

解决方案

Did you try:

println 'loading application config ...'


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

}

(this should load all Groovy files on the classpath ending with security.groovy and parse them into bean definitions).

Update: Found an interesting thread with this message as reference and my understanding is that one trick is to use ant in scripts/_Events.groovy to copy the .groovy file to the classesDirPath dir and then simply use:

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

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

This looks like a hack to get things working in both the war and when running run-app though. Not sure how things "should" be done (if this even makes sense).

这篇关于Spring bean在不同文件中的Grails配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆