ServletContextListener
全部标签 我有一个JavaEE应用程序,它应该在部署后启动一次与外部系统的同步过程。我怎样才能实现这个要求? 最佳答案 下面列出了几种在JavaEE应用程序中获取生命周期回调的流行方法。创建一个javax.servlet.ServletContextListener实现如果您的.ear文件中有一个Web组件(嵌入的.war)或者您的部署本身就是一个.war,您可以添加ServletContextListener到您的web.xml并在服务器启动或关闭时获得回调。例子:packagecom.stackoverflow.questionimpor
对于servlet生命周期的东西,你们建议如何应对异常...例如,publicclassFooimplementsServletContextListener{@OverridepublicvoidcontextInitialized(ServletContextEventevent){try{//somethingnasty}catch(Exceptione){thrownewRuntimeException(e);}}@OverridepublicvoidcontextDestroyed(ServletContextEventevent){try{//somethingnasty}
对于servlet生命周期的东西,你们建议如何应对异常...例如,publicclassFooimplementsServletContextListener{@OverridepublicvoidcontextInitialized(ServletContextEventevent){try{//somethingnasty}catch(Exceptione){thrownewRuntimeException(e);}}@OverridepublicvoidcontextDestroyed(ServletContextEventevent){try{//somethingnasty}
如果我有多个ServletContextListener并且其中一些在部署描述符中声明而其他带有注释(@WebListener),如何定义由于应用程序初始化而执行的ServletContextListener的顺序? 最佳答案 如果你想以特定顺序执行监听器,你应该使用部署描述符来定义它们。以下语句复制自ServletSpecification:8.2.3:Iftheorderinwhichthelisteners,servlets,filtersareinvokedisimportanttoanapplicationthenadep
如果我有多个ServletContextListener并且其中一些在部署描述符中声明而其他带有注释(@WebListener),如何定义由于应用程序初始化而执行的ServletContextListener的顺序? 最佳答案 如果你想以特定顺序执行监听器,你应该使用部署描述符来定义它们。以下语句复制自ServletSpecification:8.2.3:Iftheorderinwhichthelisteners,servlets,filtersareinvokedisimportanttoanapplicationthenadep
我正在将Spring插入现有的JavaEEWeb应用程序。我的web.xml中有以下几行:com.MyContextListener然后跟随MyContextListener类?publicclassMyContextListenerimplementsServletContextListener{publicvoidcontextInitialized(ServletContextEventevent){//...}}我应该怎么做才能让MyContextListener被Spring管理?已编辑:我的假设是:Spring应该创建所有servlet和所有Web应用程序基础架构,因此My
我正在将Spring插入现有的JavaEEWeb应用程序。我的web.xml中有以下几行:com.MyContextListener然后跟随MyContextListener类?publicclassMyContextListenerimplementsServletContextListener{publicvoidcontextInitialized(ServletContextEventevent){//...}}我应该怎么做才能让MyContextListener被Spring管理?已编辑:我的假设是:Spring应该创建所有servlet和所有Web应用程序基础架构,因此My
我想将一个依赖注入(inject)到ServletContextListener中。但是,我的方法不起作用。我可以看到Spring正在调用我的setter方法,但是稍后在调用contextInitialized时,该属性为null。这是我的设置:ServletContextListener:publicclassMyListenerimplementsServletContextListener{privateStringprop;/*(non-Javadoc)*@seejavax.servlet.ServletContextListener#contextInitialized(ja
我想将一个依赖注入(inject)到ServletContextListener中。但是,我的方法不起作用。我可以看到Spring正在调用我的setter方法,但是稍后在调用contextInitialized时,该属性为null。这是我的设置:ServletContextListener:publicclassMyListenerimplementsServletContextListener{privateStringprop;/*(non-Javadoc)*@seejavax.servlet.ServletContextListener#contextInitialized(ja