2、定制Servlet容器
- 实现 WebServerFactoryCustomizer<ConfigurableServletWebServerFactory>
- 把配置文件的值和
ServletWebServerFactory 进行绑定
- 修改配置文件 server.xxx
- 直接自定义 ConfigurableServletWebServerFactory
xxxxxCustomizer:定制化器,可以改变xxxx的默认规则
import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.servlet.server.ConfigurableServletWebServerFactory; import org.springframework.stereotype.Component; @Component public class CustomizationBean implements WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> { @Override public void customize(ConfigurableServletWebServerFactory server) { server.setPort(9000); } }
搜一下又有很多xxxFactoryCustomizer
然后实现接口 WebServerFactoryCustomizer<ConfigurableJettyWebServerFactory> 进入ConfigurableJettyWebServerFactory
又继承了ConfigurableWebServerFactory 进入后
这个就是默认的实现。
自己实现
public class jettyWebServerFactoryCustomizer implements WebServerFactoryCustomizer<ConfigurableJettyWebServerFactory>{
然后重写customize 方法
}
public class jettywebserverfactorycustomizer implements WebServerFactoryCustomizer<ConfigurableJettyWebServerFactory> { @Override public void customize(ConfigurableJettyWebServerFactory factory) { factory.setPort(80); } }
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/289589.html