当前位置: 首页 > news >正文

成都网站建设哪家好企业网站建设方案对比汇报

成都网站建设哪家好,企业网站建设方案对比汇报,在线制作广告,宁波seo关键词优化外包58、嵌入式Servlet容器切换web服务器与定制化 # 嵌入式Servlet容器切换与定制化 ## 切换Web服务器 ### 1. 原理 Spring Boot默认使用Tomcat作为嵌入式Servlet容器。切换其他容器#xff08;如Jetty或Undertow#xff09;的原理如下#xff1a; #### 自动配置类 - ServletWeb… 58、嵌入式Servlet容器切换web服务器与定制化 # 嵌入式Servlet容器切换与定制化 ## 切换Web服务器 ### 1. 原理 Spring Boot默认使用Tomcat作为嵌入式Servlet容器。切换其他容器如Jetty或Undertow的原理如下 #### 自动配置类 - ServletWebServerFactoryAutoConfiguration是关键的自动配置类负责创建ServletWebServerFactory。 #### 条件判断 - 根据项目中引入的依赖自动配置类会判断系统中存在哪些Web服务器相关的类。 #### 工厂类 - Spring Boot提供了多个ServletWebServerFactory实现 - TomcatServletWebServerFactory - JettyServletWebServerFactory - UndertowServletWebServerFactory - 根据条件判断选择相应的工厂类创建对应的Web服务器。 ### 2. 切换步骤 #### 排除默认Tomcat依赖 在pom.xml中排除spring-boot-starter-tomcat xml dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-web/artifactId exclusions exclusion groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-tomcat/artifactId /exclusion /exclusions /dependency #### 添加目标服务器依赖 - **切换为Jetty** xml dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-jetty/artifactId /dependency - **切换为Undertow** xml dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-undertow/artifactId /dependency ### 3. 示例 #### 切换为Jetty xml dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-web/artifactId exclusions !-- 排除Tomcat -- exclusion groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-tomcat/artifactId /exclusion /exclusions /dependency !-- 引入Jetty -- dependency groupIdorg.springframework.boot/groupId artifactIdspring-boot-starter-jetty/artifactId /dependency 重新启动应用Spring Boot将使用Jetty作为嵌入式Servlet容器。 ## 定制嵌入式Servlet容器 ### 1. 通过配置文件 在application.properties或application.yml中配置服务器属性 properties # 修改端口 server.port8081 # 设置上下文路径 server.servlet.context-path/myapp # Tomcat特有配置 server.tomcat.uri-encodingUTF-8 ### 2. 实现定制器接口 实现WebServerFactoryCustomizer接口定制ServletWebServerFactory java Configuration public class CustomServletContainerConfig implements WebServerFactoryCustomizerConfigurableServletWebServerFactory { Override public void customize(ConfigurableServletWebServerFactory factory) { // 设置端口 factory.setPort(8082); // 设置访问日志 factory.setAccessLogEnabled(true); // 其他定制... } } ### 3. 示例 #### 定制Jetty容器 java Configuration public class JettyCustomizer implements WebServerFactoryCustomizerConfigurableServletWebServerFactory { Override public void customize(ConfigurableServletWebServerFactory factory) { if (factory instanceof JettyServletWebServerFactory) { JettyServletWebServerFactory jettyFactory (JettyServletWebServerFactory) factory; // 设置Jetty特有配置 jettyFactory.addServerCustomizers(server - { // 添加连接器配置 ServerConnector connector new ServerConnector(server); connector.setPort(8083); server.addConnector(connector); }); } } } 通过以上方式可以灵活地切换和定制Spring Boot的嵌入式Servlet容器满足不同的应用需求。
http://www.w-s-a.com/news/2068/

相关文章:

  • 河南企业网站优化外包网站怎么做来流量
  • 网站建设的参考文献网站设计网页的优缺点
  • WordPress多站點支付插件内江市网站建设培训
  • 做做网站已更新动漫制作专业需要学什么
  • dfv印花图案设计网站网站建设应该应聘什么岗位
  • 网站后台管理系统模板下载专业网站推广的公司哪家好
  • 克拉玛依市建设局网站网页设计板式重构
  • 网站新闻专题怎么做湖南营销型网站建设 要上磐石网络
  • 阿里云发布网站成都轨迹公布
  • php网站源码架构谷歌站群系统
  • 潮州网站seowordpress 调用置顶文章
  • 做带会员后台的网站用什么软件旅游网站建设资金请示
  • 商品网站怎么做wordpress 表情拉长
  • 商城网站设计费用网络公司怎样推广网站
  • 视频公司的网站设计工图网
  • 免费快速网站十八个免费的舆情网站