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:
之前参考的博客:参考博客