我目前在這裏工作的是禁用webapp上下文以在Spring初始化一些bean時啓動(在初始化時調用webservices,因此是那麼可能會崩潰)。在BeanInstantiationException(Tomcat)之後禁用Spring啓動
然而,當一個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!!
但是上下文開始,至豆,這是無法啓動的引用都是空。毋庸置疑,這會導致各種不良Nullpointer異常。特別是因爲這個bean對web應用程序非常重要。
所以我需要一種方式來明確地告訴Spring,如果一個bean無法初始化,這個webapp已經無法啓動。然而System.exit(1)不是一個選項,因爲這個Tomcat服務器上還有其他的webapps。
任何想法?
看到我的答案在這裏: https://stackoverflow.com/questions/25347593/known-way-to-stop-server-when-spring-context-failed-to-load – 2015-12-02 15:03:43