EmbeddedServletContainerCustomizer被WebServerFactoryCustomizer替代


EmbeddedServletContainerCustomizer被WebServerFactoryCustomizer替代

在Spring Boot2.0以上配置嵌入式Servlet容器时EmbeddedServletContainerCustomizer类不存在,用WebServerFactoryCustomizer替代,
源码中需要添加泛型,WebServerFactory的继承接口只有ConfigurableWebServerFactory。

@FunctionalInterface
public interface WebServerFactoryCustomizer<T extends WebServerFactory> {
    void customize(T factory);
}
@Bean
    public WebServerFactoryCustomizer<ConfigurableWebServerFactory> webServerFactoryCustomizer() {

        //此接口只有一个方法,一般可以用匿名内部类进行调用
        return new WebServerFactoryCustomizer<ConfigurableWebServerFactory>() {
            @Override
            public void customize(ConfigurableWebServerFactory factory) {
                factory.setPort(8081);
            }
        };
    }

转自https://blog.csdn.net/Hard__ball/article/details/81281898


免责声明!

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



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