zoukankan      html  css  js  c++  java
  • SpringBoot定制修改Servlet容器

    1.如何修改Servlet容器的相关配置:

    第一种:在application.properties中修改和server有关的配置(ServerProperties提供);

    server.port=8081
    server.context‐path=/crud
    server.tomcat.uri‐encoding=UTF‐8
    //通用的Servlet容器设置
    server.xxx
    //Tomcat的设置
    server.tomcat.xxx

    第二种:编写一个EmbeddedServletContainerCustomizer(嵌入式Servlet容器定制器);

    @Bean

    public EmbeddedServletContainerCustomizer embeddedServletContainerCustomizer(){

      return new EmbeddedServletContainerCustomizer() {

        //定制嵌入式的Servlet容器相关的规则

        @Override

        public void customize(ConfigurableEmbeddedServletContainer container) {//传入一个可配置的嵌入式容器

          container.setPort(8083);

        }

      };

    }

    2.如何更改默认servlet容器

    该默认Tomcat为Jetty,也可以更改为Undertow

    <!‐‐ 引入web模块 ‐‐>

    <dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring‐boot‐starter‐web</artifactId>
    <exclusions>
    <exclusion>

    <!‐‐去除其Tomcat容器‐‐>
    <artifactId>spring‐boot‐starter‐tomcat</artifactId>
    <groupId>org.springframework.boot</groupId>
    </exclusion>
    </exclusions>
    </dependency>
    <!‐‐引入其他的Servlet容器‐‐>
    <dependency>
    <artifactId>spring‐boot‐starter‐jetty</artifactId>
    <groupId>org.springframework.boot</groupId>
    </dependency>

  • 相关阅读:
    java工程师面试总结
    多线程面试题
    冒个泡
    给大家简单介绍一下:Elasticsearch
    单点登录
    (jQuery)Cookie记住用户名和密码
    我们需要循序渐进的代码重构
    Java序列化(Serialization)的理解
    Java对象序列化
    【武】做一个有自控力的人,开始你的时间规划吧!
  • 原文地址:https://www.cnblogs.com/brxHqs/p/10271488.html
Copyright © 2011-2022 走看看