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

石家庄视频网站建设公司湖北seo关键词排名优化软件

石家庄视频网站建设公司,湖北seo关键词排名优化软件,wordpress隐藏外链,网站建设中怎么设置默认页58、嵌入式Servlet容器切换web服务器与定制化 # 嵌入式Servlet容器切换与定制化 ## 切换Web服务器 ### 1. 原理 Spring Boot默认使用Tomcat作为嵌入式Servlet容器。切换其他容器(如Jetty或Undertow)的原理如下: #### 自动配置类 - 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>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-web</artifactId>

    <exclusions>

        <exclusion>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-tomcat</artifactId>

        </exclusion>

    </exclusions>

</dependency>

```

#### 添加目标服务器依赖

- **切换为Jetty**:

  ```xml

  <dependency>

      <groupId>org.springframework.boot</groupId>

      <artifactId>spring-boot-starter-jetty</artifactId>

  </dependency>

  ```

- **切换为Undertow**:

  ```xml

  <dependency>

      <groupId>org.springframework.boot</groupId>

      <artifactId>spring-boot-starter-undertow</artifactId>

  </dependency>

  ```

### 3. 示例

#### 切换为Jetty

```xml

<dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-web</artifactId>

    <exclusions>

        <!-- 排除Tomcat -->

        <exclusion>

            <groupId>org.springframework.boot</groupId>

            <artifactId>spring-boot-starter-tomcat</artifactId>

        </exclusion>

    </exclusions>

</dependency>

<!-- 引入Jetty -->

<dependency>

    <groupId>org.springframework.boot</groupId>

    <artifactId>spring-boot-starter-jetty</artifactId>

</dependency>

```

重新启动应用,Spring Boot将使用Jetty作为嵌入式Servlet容器。

## 定制嵌入式Servlet容器

### 1. 通过配置文件

在`application.properties`或`application.yml`中配置服务器属性:

```properties

# 修改端口

server.port=8081

# 设置上下文路径

server.servlet.context-path=/myapp

# Tomcat特有配置

server.tomcat.uri-encoding=UTF-8

```

### 2. 实现定制器接口

实现`WebServerFactoryCustomizer`接口,定制`ServletWebServerFactory`:

```java

@Configuration

public class CustomServletContainerConfig implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {

    @Override

    public void customize(ConfigurableServletWebServerFactory factory) {

        // 设置端口

        factory.setPort(8082);

        

        // 设置访问日志

        factory.setAccessLogEnabled(true);

        

        // 其他定制...

    }

}

```

### 3. 示例

#### 定制Jetty容器

```java

@Configuration

public class JettyCustomizer implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> {

    @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.dtcms.com/wzjs/150426.html

相关文章:

  • 网站验证码文件流程优化四个方法
  • 电商网站 建社区百度推广账户登陆
  • 网站如何做生僻词引流网络媒体广告代理
  • 建设 公司 网站 请示国内免费顶级域名注册
  • 柴沟堡做网站网址seo查询
  • 做网站百度排前位seo课程培训视频
  • 洛阳做网站价格如何在百度上做推广
  • 寻找网站制作公司今日头条十大新闻
  • 网站建设目标的技术可行性中文域名的网站
  • 电影网站开发与设计深圳网络推广推荐
  • 公司做网站需要哪些资料今天最新的新闻头条
  • 烟台个人网站建设seo和sem是什么
  • 济铁工程建设集团公司官方网站短视频seo排名
  • 网站开发知识seo诊断工具
  • 彩票游戏网站开发郑州百度推广公司地址
  • 常德网站建设常德外链信息
  • 做图书馆网站的语言成都seo公司
  • java做电子政务网站系统宁波seo推广方式排名
  • 淘宝做的代码能在其他网站用吗百度网站的网址
  • 动态网站开发案例教程广告设计自学教程
  • 网站建设适应全屏如何自动刷推广链接
  • 做网站建设公司赚钱搜狗登录入口
  • excel网站链接怎么做批量酒店线上推广方案有哪些
  • 做外贸的数据网站有哪些seo搜索优化技术
  • 陕西天工建设有限公司网站网站规划
  • 网站右侧固定标题怎么做网页关键词优化软件
  • 医药公司网站模板竞价网络推广
  • 用ps做网站还是wd石家庄seo公司
  • markdown做网站模板拍照搜索百度识图
  • 便宜的网站空间网站如何做优化推广