首页 > 编程知识 正文

嵌入式Servlet容器

时间:2023-05-03 11:22:27 阅读:27773 作者:924

嵌入式servlet http://www.Sina.com /

1 .默认支持的web服务器

1. Tomcat、Jetty、Undertow

2.servletwebserverapplicationcontext容器开始搜索ServletWebServerFactory并启动服务器的创建

3 .切换服务器1. 切换嵌入式Servlet

1.spring boot APP启动发现当前导入Web APP、web场景包tomcat

2.web APP应用程序创建web版的ioc容器servletwebserverapplicationcontext

3.--servletwebserverapplicationcontext启动时查找servletwebserverfactory (servlet的web服务器工厂)

4. Springboot底层默认有很多web服务器工厂:

1.tomcatservletwebserverfactory,JettyServletWebServerFactory,undertowservletwebserverfactory

2 .底层有直接自动配置类。 servletwebserverfactoryautoconfiguraion

3.servletwebserverfactoryautoconfiguraion引入了servletwebserverfactoryconfiguration (配置类)

4.servletwebserverfactoryconfiguration配置类通过动态确定系统中导入了哪个wen服务器包,()缺省为web-starter导入tomcat

5 .创建并启动tomcatservletwebserverfactorytomcat服务器; Tomcat web server生成器包括初始化方法initialize—this.tomcat.start (;

6 .嵌入服务器是指手动调用启动服务器的代码。 (tomcat核心jar包存在。 )

原理

用于实现WebServerFactoryCustomizer并将配置文件的值绑定到ServletWebServerFactory的配置文件server.xxxconfigurableservletwebserverfactory 333

定制原理2. 定制Servlet容器

修改配置文件xxxCustomizer以创建自定义配置类xxxConfiguration @Bean,替换并添加容器中的默认组件; 查看器Web APP应用程序通过创建实现WebMvcConfigurer的配置类来定制web功能。 @Bean在容器中进一步扩展一些组件@ configurationpublicclassadminmvcconfigimplementswebmvcconfigurer @ enablewebmvcwebmvccconfigurer @ 实现w.Sina.com/webmvcautoconfiguration的默认SpringMVC自动配置功能类,包括静态资源、欢迎页面@EnableWebMvc、 会@ import (delegatingwebmvcconfiguration.class )使用delegatingwebmvcconfiguration角色只能确保SpringMVC最高所有这些组件依赖的组件都从容器中获取publicclassdelegatingwebmvcconfigurationextendswebmvconfigurationsupportwebmvcautocautoching

@ conditionalonmissingbean (webmvcconfigurationsupport.class ) @EnableWebMvc不启用WebMvcAutoConfiguration,而是http://wwwwww

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。