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>

相关文章:

  • 2022-01-16
  • 2021-08-17
  • 2021-05-08
  • 2023-03-03
  • 2022-12-23
  • 2021-05-08
  • 2022-01-24
  • 2021-10-23
猜你喜欢
  • 2022-12-23
  • 2021-12-10
  • 2022-12-23
  • 2021-08-28
  • 2021-10-29
  • 2021-05-09
  • 2022-12-23
相关资源
相似解决方案