因此,最终我找到的解决方案是:创建一个实现ServletContextListener的类,将其称为ApplicationLoaderListener。
在web.xml中设置此类:
<listener> <listener-class>com.my.package.ApplicationLoaderListener</listener-class></listener>
向其中添加一个私人成员:
private final ServletContextListener loader = new ContextLoaderListener();
此类必须实现两种接口方法,其中的一种是contextInizialized:
@Overridepublic void contextInitialized(ServletContextEvent sce) { try { loader.contextInitialized(sce); } catch (BeanCreationException e) { handle(e); }}和handle()的实现:
private void handle(BeanCreationException e) { log.error("=============== FATAL =============== - failed to create bean: ", e); System.exit(1);}为了使代码完整,第二种方法是:
@Overridepublic void contextDestroyed(ServletContextEvent sce) { loader.contextDestroyed(sce);}


