【发布时间】:2011-04-07 18:50:35
【问题描述】:
对于我目前正在从事的项目,当 spring 无法初始化某些 bean(在初始化期间调用 webservices,因此可能会崩溃)时,需要禁用要启动的 webapp 上下文。
但是,当 bean 在初始化期间抛出任何异常时,它看起来像这样:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'latestAdsRepository' defined in file [...]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [...]: Constructor threw exception; nested exception is java.io.IOException: SHUT DOWN NOW!!
...
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [...]: Constructor threw exception; nested exception is java.io.IOException: SHUT DOWN NOW!!
然而上下文开始并且所有对无法启动的bean的引用都是null。不用说,这会导致各种错误的 Nullpointer 异常。特别是因为这个 bean 对于 webapp 非常重要。
所以我需要一种方法来明确告诉 Spring,如果无法初始化 bean,则此 webapp 无法启动。然而 System.exit(1) 不是一个选项,因为在这个 Tomcat 服务器上还有其他 webapps。
有什么想法吗?
【问题讨论】:
-
在这里查看我的答案:stackoverflow.com/questions/25347593/…