⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 startuplistener.java

📁 《JSP网站开发典型模块与实例精讲》一书光盘源码
💻 JAVA
字号:
package org.appfuse.webapp.listener;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.appfuse.Constants;
import org.appfuse.util.ServiceFactory;
//import com.aspire.demo.service.TestService;

/**
 * StartupListener class used to initialize Spring bean config.
 *
 *
 */
public class StartupListener extends ContextLoaderListener
    implements ServletContextListener {

    private static final Log log = LogFactory.getLog(StartupListener.class);

    public void contextInitialized(ServletContextEvent event) {
        if (log.isDebugEnabled()) {
            log.debug("initializing context...");
        }

        // call Spring's context ContextLoaderListener to initialize
        // all the context files specified in web.xml
        super.contextInitialized(event);

        ServletContext context = event.getServletContext();

        // Orion starts Servlets before Listeners, so check if the config
        // object already exists
//        Map config = (HashMap) context.getAttribute(Constants.CONFIG);
//
//        if (config == null) {
//            config = new HashMap();
//        }
//        context.setAttribute(Constants.CONFIG, config);
//
        setupContext(context);
    }

    public static void setupContext(ServletContext context) {
        ApplicationContext ctx =
            WebApplicationContextUtils.getRequiredWebApplicationContext(context);

        // Initial ServiceFactory
        ServiceFactory.init(ctx);

        // TestService service = (TestService) ctx.getBean("testService");

        if (log.isDebugEnabled()) {
            log.debug("drop-down initialization complete [OK]");
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -