views:

44

answers:

1

I'm building a Grails (1.3.4) app configured with the grails plugin tomcat-1.3.4 and using Spring (3.0.3RELEASE) but reusing an existing Spring applicationContext.xml file. I copied the relevant portions of the old file into the one generated by Grails (just below the characterEncodingFilter bean). After making sure that all the required jars were on the classpath, and that there was no conflict in bean names (I found out that dataSource was already used if the DataSource.groovy file exists, so I deleted it to resolve that), I am faced with an IllegalStateException. The stacktrace and a bit of the debug log leading it is as follows:

2010-09-30 15:29:36,131 [main] DEBUG xml.DefaultDocumentLoader  - Using JAXP provider [com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl]
2010-09-30 15:29:36,143 [main] DEBUG support.DefaultListableBeanFactory  - Returning cached instance of singleton bean 'grailsApplication'
2010-09-30 15:29:36,149 [main] ERROR context.GrailsContextLoader  - Error executing bootstraps: postProcessBeanDefinitionRegistry already called for this post-processor
    java.lang.IllegalStateException: postProcessBeanDefinitionRegistry already called for this post-processor
    at org.grails.tomcat.TomcatServer.start(TomcatServer.groovy:164)
    at grails.web.container.EmbeddableServer$start.call(Unknown Source)
    at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy:158)
    at _GrailsRun_groovy$_run_closure5_closure12.doCall(_GrailsRun_groovy)
    at _GrailsSettings_groovy$_run_closure10.doCall(_GrailsSettings_groovy:280)
    at _GrailsSettings_groovy$_run_closure10.call(_GrailsSettings_groovy)
    at _GrailsRun_groovy$_run_closure5.doCall(_GrailsRun_groovy:149)
    at _GrailsRun_groovy$_run_closure5.call(_GrailsRun_groovy)
    at _GrailsRun_groovy.runInline(_GrailsRun_groovy:116)
    at _GrailsRun_groovy.this$4$runInline(_GrailsRun_groovy)
    at _GrailsRun_groovy$_run_closure1.doCall(_GrailsRun_groovy:59)
    at RunApp$_run_closure1.doCall(RunApp.groovy:33)
    at gant.Gant$_dispatch_closure5.doCall(Gant.groovy:381)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy:415)
    at gant.Gant$_dispatch_closure7.doCall(Gant.groovy)
    at gant.Gant.withBuildListeners(Gant.groovy:427)
    at gant.Gant.this$2$withBuildListeners(Gant.groovy)
    at gant.Gant$this$2$withBuildListeners.callCurrent(Unknown Source)
    at gant.Gant.dispatch(Gant.groovy:415)
    at gant.Gant.this$2$dispatch(Gant.groovy)
    at gant.Gant.invokeMethod(Gant.groovy)
    at gant.Gant.executeTargets(Gant.groovy:590)
    at gant.Gant.executeTargets(Gant.groovy:589)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:115)

Update: If I comment out the following lines at the top of my applicationContext.xml, it goes into an infinite loop.

<context:annotation-config/>
<context:property-placeholder location="WEB-INF/config.properties"/>

If I also comment out my import lines, it runs as expected. The import lines are:

<import resource="conf/membershipData.xml"/>
<import resource="conf/membershipServices.xml"/>

/Update

Tracing down through the debugger, I noticed that it occurs during a refresh of the applicationContext during start up (DefaultRuntimeSpringConfiguration:154).

In case it is relevant, I'm using IntelliJ IDEA 9, which is handling all of the jar insertions before the run-app command.

Thanks for your help.

A: 

You shouldn't touch applicationContext.xml - that's for the "parent" application context. Copy your beans into resources.xml under grails-app/conf/spring. This file is no longer created by default since the preferred approach is to use the Spring bean DSL in resources.groovy, but the format of resources.xml is just the standard Spring bean xml, so you could probably just copy your xml file there and rename it to resources.xml.

Burt Beckwith
It's good to know that I'm not supposed to touch that parent context file. I'm in the process of moving my declarations down into the resources.xml file in the proper place now. Once I get it to read a config.properties file from where it is (it sees the properties file, but is no longer replacing the keys in the xml files with their values, and doesn't take any of the ones from Config.groovy) I'll come back and verify your answer. Thanks Burt!
Shawn D