开发者

Grails config of Spring beans in different files

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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜