0
点赞
收藏
分享

微信扫一扫

springboot @WebServlet为什么能生效

示意图

springboot @WebServlet为什么能生效_spring

简述

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中。

举报

相关推荐

0 条评论