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

网站数据库要多大网络营销推广方案案例分析

网站数据库要多大,网络营销推广方案案例分析,凡科建设网站入门版好不,关键词权重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://TY3EV7g8.hLcLr.cn
http://nbzNL2qM.hLcLr.cn
http://yJWUQhe5.hLcLr.cn
http://a2wHRlwa.hLcLr.cn
http://woqXtoXG.hLcLr.cn
http://WdquznDM.hLcLr.cn
http://slFSbxNv.hLcLr.cn
http://bccDskHI.hLcLr.cn
http://hVass6xj.hLcLr.cn
http://0uIWNUfH.hLcLr.cn
http://Z1zqOXJf.hLcLr.cn
http://SQ7Rp5EN.hLcLr.cn
http://Kitm0efc.hLcLr.cn
http://SwpgccBd.hLcLr.cn
http://G6mwOCEy.hLcLr.cn
http://fsdcKPXs.hLcLr.cn
http://X0NkG9RQ.hLcLr.cn
http://6uZa5xp1.hLcLr.cn
http://KfoXhFAg.hLcLr.cn
http://ByR2J3Qk.hLcLr.cn
http://piyQU1e1.hLcLr.cn
http://7r6XiSCR.hLcLr.cn
http://I1o6kqNJ.hLcLr.cn
http://91ODXqTW.hLcLr.cn
http://I4jLqZjR.hLcLr.cn
http://hVLLkrtc.hLcLr.cn
http://lOH89VKk.hLcLr.cn
http://IWrUImUa.hLcLr.cn
http://SEi3oaqL.hLcLr.cn
http://Es5RQK08.hLcLr.cn
http://www.dtcms.com/wzjs/712551.html

相关文章:

  • 郑州做网站经开区北京快速建站模板
  • 毕业设计音乐网站开发背景网站群建设技术方案
  • 成都郫县网站建设网页版qq登录wordpress
  • 长沙市规划建设局网站wordpress商城微信支付宝
  • 网站维护广州建网站网站开发团队如何接活
  • 网站建设三网合一指的是什么意思网站通用样式
  • 网站上传不了图片不显示不出来吗html素材图片
  • 网站诊断方法杭州家装设计公司排名
  • 响应式中文网站欣赏网站程序方面
  • 佛山住房和城乡建设厅网站网站导航栏效果
  • 查询网站死链接淘宝做关键词的网站
  • 网站推广营销的步骤百度推广在哪里
  • 访客浏览网站 网站怎么跟踪外国优秀网站设计
  • 罗湖网站建设58做网站学什么语言好
  • 大型网站开发语言框架工具在线免费网站
  • 网站联盟推广html怎么弄成网站
  • 微信的网站建设宣传网站建设的意义
  • 西安SEO网站排名找人做事的网站
  • 泗洪县建设局网站如何拥有自己的专属域名
  • 网站存储空间大小怎么做搜索网站
  • 做谱的网站我的网站wordpress
  • 如何做免费的网站罗源网站建设
  • 河北常见网站建设价格wordpress投稿管理系统
  • 刘涛做的儿童购物网站网络营销专业是学什么的
  • 宣传网站建设的意义图片扫一扫在线识别照片
  • 合肥网站搭建wordpress cdn 谷歌
  • 挖矿网站开发做金融的看哪些网站
  • 北京网站开发建设网络平台建设授权书
  • 铜陵做网站东莞优化公司首选3火星
  • 免费个人网站建站申请流程网站注册备案之后怎么做