示意图
简述
1. springboot 启动类通过注解 @ServletComponentScan,注入了指定的BeanFactoryPostProcessor,用来扫描@WebServlet 等指定的类,将扫描到的LoginServlet类作为ServletRegistrationBean属性,将ServletRegistrationBean注册到容器中。
2. Tomcat启动,通过StandardContext启动,通过查找所有的ServletRegistrationBean类的Bean,依次调用Bean对象的onStartup方法,将捆绑的servlet属性通过context.addServlet添加到context中。
3. 业务处理请求,通过nioEndpoint,CoyoteAdapter,将请求依次传递到engine、host、context、servlet处理。
关键代码入口
1. org.springframework.boot.web.servlet.WebServletHandler#doHandle 注册ServletRegistrationBean 到容器
2. org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext#selfInitialize 找到所有的ServletRegistrationBean对象,依次调用onStartup方法
3. org.springframework.boot.web.servlet.ServletRegistrationBean#addRegistration servlet注册context中
4. org.apache.catalina.connector.CoyoteAdapter#service 处理请求,转发到engin中。
标签:web,ServletRegistrationBean,boot,WebServlet,context,生效,org,servlet,springboot From: https://blog.51cto.com/u_15913327/5983804