All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.ajaxjs.spring.BaseWebInitializer Maven / Gradle / Ivy

package com.ajaxjs.spring;

import com.ajaxjs.util.logger.LogHelper;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.XmlWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration;

/**
 * 配置 Spring MVC
 *
 * @author Frank Cheung
 */
public abstract class BaseWebInitializer implements WebApplicationInitializer {
    private static final LogHelper LOGGER = LogHelper.getLog(BaseWebInitializer.class);

    @Override
    public void onStartup(ServletContext servletContext) {
        LOGGER.info("WEB 程序启动中……");
        XmlWebApplicationContext ctx = new XmlWebApplicationContext();
        ctx.setConfigLocation("/WEB-INF/spring-mvc.xml");

        String initParameter = servletContext.getInitParameter("SpringMVC_Mapping");

        ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));
        servlet.addMapping(initParameter == null ? "/" : initParameter);
        servlet.setLoadOnStartup(1);
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy