在取消部署应用程序时触发功能 [英] Trigger function when Undeploying application
本文介绍了在取消部署应用程序时触发功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我在Glassfish中部署/取消部署/重新部署JEE5应用程序时,如何自动触发Java函数来停止Quartz调度程序作业。
解决方案
执行 ServletContextListener
并钩上 contextDestroyed()
基本示例:
public class Config implements ServletContextListener {
public void contextInitialized(ServletContextEvent event){
//在这里编写应该在webapp启动时执行的代码。
public void contextDestroyed(ServletContextEvent event){
//在这里写代码应该在webapp关闭时执行。
}
}
并将其注册为< listener>
in web.xml
。
< listener>
< listener-class> com.example.Config< / listener-class>
< / listener>
How do I automatically trigger Java function to stop Quartz scheduler jobs when I deploy/undeploy/redeploy JEE5 application in Glassfish.
解决方案
Implement ServletContextListener
and hook on contextDestroyed()
.
Basic example:
public class Config implements ServletContextListener {
public void contextInitialized(ServletContextEvent event) {
// Write code here which should be executed on webapp startup.
}
public void contextDestroyed(ServletContextEvent event) {
// Write code here which should be executed on webapp shutdown.
}
}
and register it as a <listener>
in web.xml
.
<listener>
<listener-class>com.example.Config</listener-class>
</listener>
这篇关于在取消部署应用程序时触发功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文