1

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 :(

Igor Artamonov
  • 35,450
  • 10
  • 82
  • 113

1 Answers1

1

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

Pascal Thivent
  • 562,542
  • 136
  • 1,062
  • 1,124
  • tried, but with no success :( And also there aro no any security.groovy anywhere in classpath, grails compiled it into security.class I thins that it the root of problem, but don't know how to fix this – Igor Artamonov Feb 16 '10 at 22:46
  • @Pascal Thivent Can you re-post / update the links to Nabble? They appear to be missing... – leeand00 Oct 04 '11 at 21:12
  • I tried the following in _Event and it worked. eventCompileEnd = { ant.copy(file: "${basedir}/grails-app/conf/spring/security.groovy", todir: classesDirPath) } – amoran Dec 09 '11 at 03:02