如果在应用程序初始化期间发生异常,是否有任何方法来阻止
Java EE应用程序启动?在应用程序初始化期间,从
ServletContextListener或
Singleton
Startup bean抛出的未处理异常之后,我基本上正在寻找一种方法来使应用程序进入“j2ee.state.failed”状态(每
JSR-77).
EJB specification似乎表明,如果在初始化Singleton bean时发生异常,应用程序将继续启动并运行而没有错误;但是,只有bean本身可能处于无法调用的状态.不幸的是,这不是我正在寻找的行为.
4.8.4 Singleton Error Handling
Errors occurring during Singleton initialization are considered fatal and must result in the discarding of the Singleton instance. Possible initialization errors include injection failure, a system exception thrown from a PostConstruct method, or the failure of a PostConstruct method container-managed transaction to successfully commit. If a singleton fails to initialize, attempted invocations on the Singleton result in an exception as defined by Section 3.4.3 and Section 3.4.4.
Servlet specification的要求有点更加模糊,似乎不要求容器以任何特定的方式表现,而只是建议(通过使用术语“可能”)Web模块继续启动,但任何请求都应该产生在内部服务器错误.再次,这不幸不是我正在寻找的行为.如果Web应用程序无法处理任何请求,应该继续启动并显示为运行?
11.6 Listener Exceptions
The container may respond to all subsequent requests to the Web application with an HTTP status code 500 to indicate an application error.
根据我的经验,我看到应用服务器以不同的方式处理这个需求.实际上,有些容器在这些情况下实际上会阻止应用程序启动,而其他的容器将只会抑制异常,并响应500个错误的请求,如规范中所述.
我是否忽略了在初始化过程中发生异常时防止应用程序启动的规范的任何部分?