java 如何调试 ContextLoader - 上下文初始化失败和 BeanCreationException
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3834733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to debug ContextLoader - Context initialization failed and BeanCreationException
提问by Sunny
I see a number of posts on the various problems folks have with troubleshooting this problem: ERROR context.ContextLoader - Context initialization failedorg.springframework.beans.factory.BeanCreationException:
我看到许多关于人们在解决此问题时遇到的各种问题的帖子: ERROR context.ContextLoader - Context initialization failedorg.springframework.beans.factory.BeanCreationException:
Is there a way to turn on debugging to isolate the problem?
有没有办法打开调试来隔离问题?
Its complaining about "No such property: getOrg for class: groovy.lang.MetaClassImpl" but that's not directly one one of our classes, is there some way to get info that's relevant to our codebase?
它抱怨“没有这样的属性:getOrg for class: groovy.lang.MetaClassImpl”但这不是我们的直接类之一,有什么方法可以获得与我们的代码库相关的信息吗?
In our case we had a Grails 1.2.1 app deployed and running just fine in Tomcat. We then stopped Tomcat to do a DB backup and then restarted the app. The same WAR with no environmental changes(i.e, no config file changes, etc.) now throws this error. We had observed this behavior intermittently previously as well, but restarting used to fix the prob.
在我们的例子中,我们部署了一个 Grails 1.2.1 应用程序,并且在 Tomcat 中运行得很好。然后我们停止 Tomcat 以进行数据库备份,然后重新启动应用程序。没有环境更改(即,没有配置文件更改等)的相同 WAR 现在会引发此错误。我们之前也曾间歇性地观察到这种行为,但重新启动用于解决问题。
In our development environment, the same app runs just fine with "grails prod run-app" as well as "grails prod run-war".
在我们的开发环境中,同一个应用程序可以在“grails prod run-app”和“grails prod run-war”下正常运行。
The stacktrace snippets:
堆栈跟踪片段:
2010-09-30 12:10:13,391 ERROR context.ContextLoader - Context initialization failed org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageSource': Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transactionManager': Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory': Invocation of init method failed; nested exception is groovy.lang.MissingPropertyException: No such property: getOrg for class: groovy.lang.MetaClassImpl at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519) at org.codehaus.groovy.grails.commons.spring.ReloadAwareAutowireCapableBeanFactory.doCreateBean(ReloadAwareAutowireCapableBeanFactory.java:129) at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:450) at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:290) at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222)
2010-09-30 12:10:13,391 错误 context.ContextLoader - 上下文初始化失败 org.springframework.beans.factory.BeanCreationException:创建名为“messageSource”的 bean 时出错:bean 初始化失败;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“transactionManager”的 bean 时出错:设置 bean 属性“sessionFactory”时无法解析对 bean“sessionFactory”的引用;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“sessionFactory”的 bean 时出错:调用 init 方法失败;嵌套异常是 groovy.lang.MissingPropertyException: No such property: getOrg for class: groovy.lang.MetaClassImpl at org.springframework.beans.factory.support。
<<<<<<<< snip >>>>>>>>>>>>>>>>>>>>>>
<<<<<<<< 截图 >>>>>>>>>>>>>>>>>>>>>>
Caused by: groovy.lang.MissingPropertyException: No such property: getOrg for class: groovy.lang.MetaClassImpl
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:49)
at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.setProperty(ScriptBytecodeAdapter.java:485)
at org.codehaus.groovy.grails.plugins.orm.hibernate.HibernatePluginSupport.handleLazyProxy(HibernatePluginSupport.groovy:413)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.bindProperty(GrailsDomainBinder.java:2108)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.createProperty(GrailsDomainBinder.java:1829)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.createClassProperties(GrailsDomainBinder.java:1565)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.bindJoinedSubClass(GrailsDomainBinder.java:1272)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.bindSubClass(GrailsDomainBinder.java:1219)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.bindSubClasses(GrailsDomainBinder.java:1186)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.bindRoot(GrailsDomainBinder.java:1160)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsDomainBinder.bindClass(GrailsDomainBinder.java:1040)
at org.codehaus.groovy.grails.orm.hibernate.cfg.GrailsAnnotationConfiguration.secondPassCompile(GrailsAnnotationConfiguration.java:145)
at org.hibernate.cfg.Configuration.buildMappings(Configuration.java:1148)
at org.springframework.orm.hibernate3.LocalSessionFactoryBean.buildSessionFactory(LocalSessionFactoryBean.java:717)
at org.springframework.orm.hibernate3.AbstractSessionFactoryBean.afterPropertiesSet(AbstractSessionFactoryBean.java:211)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1460)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1398)
回答by uthark
If you set logging level to DEBUGfor packages org.springframeworkand org.codehaus.groovythen you will be able to get more details.
如果您将日志级别设置DEBUG为包org.springframework,org.codehaus.groovy那么您将能够获得更多详细信息。
But in case of grails sometimes it helps just to stop tomcat, remove workand tempdirectories and start tomcat again.
但是在 grails 的情况下,有时它有助于停止 tomcat,删除work和temp目录并再次启动 tomcat。
回答by Dan Lynn
I've gotten this in grails 1.3.4, and removing the tomcat work and temp directories ($CATALINA_BASE/temp, $CATALINA_BASE/work) does seem to fix the problem.
我在 grails 1.3.4 中得到了这个,删除 tomcat 工作和临时目录($CATALINA_BASE/temp,$CATALINA_BASE/work)似乎确实解决了这个问题。

