SpringBoot | 关于SpringBoot2.x以上版本废弃EmbeddedServletContalnerCustomizer

springboot1.x版本中修改嵌入式Servlet容器配置的方法

在Springboot1.x的版本中有EmbeddedServletContalnerCustomizer类,该类可以来修改嵌入式Servlet容器的配置。

当我学习到此处时,由于教程使用的SpringBoot版本是1.x,所以自己在实践时没有找到EmbeddedServletContalnerCustomizer类,通过网上找资料发现在SpringBoot2.x中并没有这个类,2.x版本使用了WebServerFactoryCustomizer来代替EmbeddedServletContalnerCustomizer

WebServerFactoryCustomizer用法

@Configuration
public class MyMvcConfig implements WebMvcConfigurer{
    
    
    @Bean
    public WebServerFactoryCustomizer webServerFactoryCustomizer(){
    
    
        return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
    
    

            //定制嵌入式的Servlet容器相关的规则
            @Override
            public void customize(ConfigurableWebServerFactory factory) {
    
    
              	//将端口号改为8083
                factory.setPort(8083);
            }

        };
    }
}

重启Springboot,发现其端口号已改变为8083:

之前参考的博客:参考博客

猜你喜欢

转载自blog.csdn.net/qq_14810195/article/details/105056539
今日推荐