mat*_*att 5 java spring tomcat
对于我目前正在工作的项目,当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!!
Run Code Online (Sandbox Code Playgroud)
但是上下文开始,并且对无法启动的bean的所有引用都为null.不用说,这会导致各种各样糟糕的Nullpointer Exceptions.特别是因为这个bean对于webapp非常重要.
因此,我需要一种方法来明确告诉Spring,如果无法初始化bean,则此webapp无法启动.但是,System.exit(1)不是一个选项,因为此Tomcat服务器上还有其他Web应用程序.
有任何想法吗?
据我所知,默认情况下,当 Spring 无法实例化 bean 时,如果异常通过启动侦听器传播到 servlet 容器,则上下文启动会失败。
您可以使用@Required注释将某个注入点标记为强制注入点。
| 归档时间: |
|
| 查看次数: |
2850 次 |
| 最近记录: |