• Springboot中如何启用多个监听端口


    前段时间服务有这么个需求,web端的接口需要有web安全相关的整改,但是对内的接口并不需要。所以服务需要多个端口启动,在此记录下

    Springboot中如何启用多个监听端口

    @Configuration
    public class EmbeddedTomcatConfiguration {
     
        @Value("${server.additionalPorts}")
        private String additionalPorts;
     
        @Bean
        public EmbeddedServletContainerFactory servletContainer() {
            TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
            Connector[] additionalConnectors = this.additionalConnector();
            if (additionalConnectors != null && additionalConnectors.length > 0) {
                tomcat.addAdditionalTomcatConnectors(additionalConnectors);
            }
            return tomcat;
        }
     
        private Connector[] additionalConnector() {
            if (StringUtils.isBlank(this.additionalPorts)) {
                return null;
            }
            String[] ports = this.additionalPorts.split(",");
            List<Connector> result = new ArrayList<>();
            for (String port : ports) {
                Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
                connector.setScheme("http");
                connector.setPort(Integer.valueOf(port));
                result.add(connector);
            }
            return result.toArray(new Connector[] {});
        }
    }

    application.yml

    server:
      port: ${appPort:8800}
      additionalPorts: 8881,8882
    博客园:https://www.cnblogs.com/xianquan
    Copyright ©2020 l-coil
    【转载文章务必保留出处和署名,谢谢!】
  • 相关阅读:
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    xgqfrms™, xgqfrms® : xgqfrms's offical website of GitHub!
    http 请求code状态码
    js 跳转链接
    a标签-伪类
    在linux中如何解压.tgz
    dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.63.dylib
    nginx: [warn] conflicting server name "localhost" on 0.0.0.0:80, ignored
    微信小程序实现左滑删除效果(原生/uni-app)
  • 原文地址:https://www.cnblogs.com/xianquan/p/13019040.html
  • Copyright © 2020-2023  润新知