在SpringBoot面世之前。在一般的WEB项目中,项目的启动都是从web.xml开始的,如果我们想在项目中使用Spring,只需在web.xml文件中指定以下内容即可:
路径为/src/main/webapp/WEB-INF/web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
package com.xxx.listener;
import javax.servlet.ServletContext;
import org.springframework.web.context.WebApplicationContext;
import com.jeeplus.modules.sys.service.SystemService;
public class WebContextListener extends org.springframework.web.context.ContextLoaderListener {
@Override
public WebApplicationContext initWebApplicationContext(ServletContext servletContext) {
if (!SystemService.printKeyLoadMessage()){
return null;//自己代码处理
}
return super.initWebApplicationContext(servletContext);
}
}