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