Spring Boot2.0以上版本EmbeddedServletContainerCustomizer被WebServerFactoryCustomizer替


在Spring Boot2.0以上配置嵌入式Servlet容器时EmbeddedServletContainerCustomizer类不存在,查询发现被WebServerFactoryCustomizer替代

clipboard

       使用WebServerFactoryCustomizer接口替换EmbeddedServletContainerCustomizer组件完成对嵌入式Servlet容器的配置

配置代码如下:

【注意】 springboot 2.0.1以上需要用 MyServerConfig
/**
 * @author houChen
 * @date 2020/6/23 6:47
 * @Description:  server 相关的配置类
 */
public class MyServerConfig {

    //编写一个*EmbeddedServletContainerCustomizer:
    // 嵌入式的Servlet容器的定制器;来修改Servlet容器的配置
    @Bean  //一定要将这个定制器加入到容器中
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer(){
        return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {

            @Override
            public void customize(ConfigurableWebServerFactory factory) {
                factory.setPort(8081);
            }
        };
    }
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM