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>

  • 相关阅读:
    个人阅读作业Week7
    个人博客作业week3——案例分析
    结对项目——高级四则运算检验器记录(168 & 187)
    个人博客作业week2——代码复审
    个人项目---四则运算题目生成器项目记录
    第一次博客作业
    JAVA编程入门
    计算机基础知识点总结
    Java数据类型总结1
    JAVA编程入门
  • 原文地址:https://www.cnblogs.com/brxHqs/p/10271488.html
Copyright © 2011-2022 走看看