如何在关闭web服务时进行一些清理操作(Spring mvc)

背景

目前正在替一家500强企业开发系统,因为系统众多所以他们使用ESB对各个系统之间的服务进行管理,同样也要求我们的系统进行对接。要求在我们的系统启动时进行注册,在系统关闭时进行注销。根据要求同事写了一个serverlet在系统启动的时候进行注册操作,但是不知道在系统关闭时进行相应的操作。

解决方法

因为项目使用spring mvc 项目,所以我知道可以通过spring的监听器完成相应的工作。
步骤1:实现ApplicationListener 

package com.efuture.vpm.util;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;


public class ApplicationEventListener implements ApplicationListener {
protected final Log log = LogFactory.getLog(getClass());
	public void onApplicationEvent(ApplicationEvent event) {
	
		 //容器关闭时触发的事件
		if(event instanceof ContextClosedEvent ){
			
			log.info("application close       1111111111111111111111111111111111111     ");
		}else{
			log.info("application ohter event       222222222222222222222222222222222222222     ");
			
		}
	
	}
}

步骤2: 配置

 <!-- 应用级的监听器 (注销esb) -->
     <bean id="sytemEventListener" class="com.efuture.vpm.util.ApplicationEventListener"></bean>
    

备注:

关闭事件的触发仅限于正常方式关闭服务器,而不是直接关闭 console窗口这样的方式。



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值