我正在使用grails插件tomcat-1.3.4构建一个Grails(1.3.4)应用程序并使用Spring(3.0.3RELEASE)但重用现有的Spring applicationContext.xml文件。我将旧文件的相关部分复制到Grails生成的部分(在characterEncodingFilter bean下面)。确保所有必需的jar都在类路径上,并且bean名称没有冲突(我发现如果DataSource.groovy文件存在,则已经使用了dataSource,所以我删除它以解决它),我是面临IllegalStateException。堆栈跟踪和一些调试日志如下所示:
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)
更新: 如果我在applicationContext.xml的顶部注释掉以下行,它将进入无限循环。
<context:annotation-config/>
<context:property-placeholder location="WEB-INF/config.properties"/>
如果我也注释掉我的导入行,它会按预期运行。导入行是:
<import resource="conf/membershipData.xml"/>
<import resource="conf/membershipServices.xml"/>
/更新
通过调试器进行跟踪,我注意到它在启动期间刷新applicationContext期间发生(DefaultRuntimeSpringConfiguration:154)。
如果它是相关的,我正在使用IntelliJ IDEA 9,它在run-app命令之前处理所有jar插入。
感谢您的帮助。
答案 0 :(得分:2)
您不应该触及applicationContext.xml - 这是“父”应用程序上下文。将bean复制到grails-app / conf / spring下的resources.xml中。默认情况下不再创建此文件,因为首选方法是在resources.groovy中使用Spring bean DSL,但resources.xml的格式只是标准的Spring bean xml,因此您可能只需将xml文件复制到那里,将其重命名为resources.xml。