简体   繁体   English

如何在 Spring Boot 的不同端口上注册 servlet?

[英]How to register servlet on a different port in spring boot?

In my casual spring boot application I regiser servlet like this.在我的休闲 Spring Boot 应用程序中,我像这样注册 servlet。

    import io.prometheus.client.exporter.*
    .....
    @Bean
    public ServletRegistrationBean<MetricsServlet> registerMetricsServlet(MetricRegistry metricRegistry) {
        return new ServletRegistrationBean<>(new MetricsServlet(), "/metrics");
    }

This servlet is registred on the same port as application.此 servlet 注册在与应用程序相同的端口上。 The issue is that my infrastructure(k8s and etc) is expecting that application and metrics endpoint works on a different ports(like actuator does).问题是我的基础设施(k8s 等)期望应用程序和指标端点在不同的端口上工作(如执行器)。

How can I register third party servlet on a ddifferent port ?如何在不同的端口上注册第三方 servlet?

You can do it with multiple connectors and request filter.您可以使用多个连接器和请求过滤器来做到这一点。 (All connectors are handle same way) (所有连接器的处理方式相同)

  1. https://tech.asimio.net/2016/12/15/Configuring-Tomcat-to-Listen-on-Multiple-ports-using-Spring-Boot.html https://tech.asimio.net/2016/12/15/Configuring-Tomcat-to-Listen-on-Multiple-ports-using-Spring-Boot.html

pay attention to the lines from注意从

   public FilterRegistrationBean javaMelodyRestrictingFilter(FilterRegistrationBean javaMelodyFilter) {...
  1. spring boot 2.0 listening on multiple ports spring boot 2.0 监听多个端口

Original answer here.原始答案在这里。 Configure Spring Boot with two ports 使用两个端口配置 Spring Boot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM