如何手动控制spring容器的加载

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.springframework.web.context.ContextLoaderListener;
import com.huaweisymantec.ecm.util.EcmUtils;

/**
 *
 * 自定义应用程序监听器
 *
 * 控制Spring Listener的加载<br>
 * 因为本系统需要进行初始化配置才加载Spring框架,因此注释了web.xml中的
 * Spring自动加载的listener。通过我们自定的listener判断初始化成功之后才进行加载。
 *
 * @author w90006039
 */
public class EcmListener implements ServletContextListener {

    private static ContextLoaderListener springListener;
    private static ServletContextEvent event;

    /**
     * 初始化Spring配置
     *
     */
    public static void initSpringConfig() {
        if (null != event) {
            initListener();
            springListener.contextInitialized(event);
        }
    }

    /**
     * 初始化监听器
     *
     */
    private static void initListener() {
        if (null == springListener) {
            springListener = new ContextLoaderListener();
        }
    }

    /**
     * 停止系统方法 </br>
     * 包括停止任务线程
     *
     */
    public void contextDestroyed(ServletContextEvent arg0) {
        if (null != springListener) {
            springListener.contextDestroyed(event);
        }
    }
   
    /**
     * 监听,如果已经初始化则启动spring框架
     */
    public void contextInitialized(ServletContextEvent arg0) {
        event = arg0;
        if (EcmUtils.isSystemInited()) {
            initSpringConfig();
        }
    }

}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值