spring-boot - Which piece of code actually register dispatcher servlet for springMVC?

后端 未结 3 1109
遇见更好的自我
遇见更好的自我 2020-12-13 11:17

I am trying to find out in spring-boot, which implementation of WebApplicationInitializer actually register the dispatcher servlet.

I didn\

3条回答
  •  余生分开走
    2020-12-13 12:20

    If you want to deploy the Spring Boot application as a traditional WAR, then the Servlet 3.0 specification details how service providers can set it up so that the 3.0 compliant servlet container will automatically bootstrap any web assets (Servlet, Filter, ServletContextInitializer's) into the servlet container. The "magic" is accomplished in the spring-web dependency. If you un'jar it, you'll find file "spring-web/META-INF/services/javax.servlet.ServletContainerInitializer". Open the file and you'll see single line "org.springframework.web.SpringServletContainerInitializer". This class delegates to all classes that implement WebApplicationInitializer, more specifically their onStartup(ServletContext servletContext) method. There's one such concrete class I'm aware of in Spring Boot, namely SpringBootServletInitializer.

提交回复
热议问题