首页 > 编程学习 > 定制Servlet容器--xxxCustomizer

定制Servlet容器--xxxCustomizer

发布时间:2022/9/15 4:28:06

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);
    }
}

 

Copyright © 2010-2022 mfbz.cn 版权所有 |关于我们| 联系方式|豫ICP备15888888号