【springboot】修改Servlet容器的相关配置

方法一,直接在application.properties 配置文件中配置

server.port=8081

方法二,用WebServerFactoryCustomizer配置器配置

在springboot 1.xxx版本中用EmbeddedServletContainerCustomizer嵌入式的Servlet容器来来修改Servlet容器的配置,但在 springboot 2.0以上EmbeddedServletContainerCustomizer已经不能使用,而用WebServerFactoryCustomizer也可以实现Servlet容器的相关配置。

@Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> myWebServerFactoryCustomizer(){
    
    
       return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
    
    
           @Override
           public void customize(ConfigurableWebServerFactory factory) {
    
    
               factory.setPort(8081);
           }
       };
    }

猜你喜欢

转载自blog.csdn.net/Black_Customer/article/details/107731967
今日推荐