文章目录
- 1 从servlet3.0的特性说起
-
- 1.1 web应用启动, 会创建当前Web应用导入jar包中的 ServletContainerInitializer类的实例
- 1.2 ServletContainerInitializer 类必须放在jar包的 META-INF/services目录下,文件名称为 javax.servlet.ServletContainerInitializer
- 1.3 文件的内容指向ServletContainerInitializer实现类的全路径
- 1.4 使用@HandlesTypes在我们应用启动的时候,加载我们感兴趣的类
- 2 Spring Boot启动War包流程图
前情提示:以前我们说过,springboot程序是jar的方式,是通过IOC容器启动带动了tomcat的启动
那么,我们把springboot的程序打成war的时候,是怎么样的原理了?(tomcat启动带动IOC容器的启动)
从疑问开始: 我们把springboot打成war的包时候,为什么要在启动类程序上实现 SpringBootServletInitializer 接口?
以及com.tuling.TulingvipSpringbootWarApplication#configure()是在什么时候触发调用的?
@SpringBootApplication
public class TulingvipSpringbootWarApplication extends SpringBootServletInitializer {
public static void main(String[] args) {
SpringApplication.run(TulingvipSpringbootWarApplication.class, args);
}
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(TulingvipSpringbootWarApplication.class);
}
}
1 从servlet3.0的特性说起
8.2.4 Shared libraries / runtimes pluggability
The ServletContainerInitializer class is looked up via the jar services API. For each application, an instance of the ServletContainerInitializer is created by the container at application startup time. The framework providing an implementation of the ServletContainerInitializer MUST bundle in the META-INF/services directory of the jar file a file called javax.servlet.ServletContainerInitializer, as per the jar services API,that points to the implementation class of the ServletContainerInitializer. In addition to the ServletContainerInitializ