Java Prometheus ServletRegistrationBean在某些工作区中不工作

Java Prometheus ServletRegistrationBean在某些工作区中不工作,java,spring-boot,prometheus,Java,Spring Boot,Prometheus,我想监控一些应用程序,我正在使用普罗米修斯。它在某些应用程序中运行良好,但当我尝试在另一个应用程序中实现它时,我遇到了一些问题。 它说: 构造函数ServletRegistrationBean(MetricsServlet,String)未定义 什么会导致此问题以及如何解决此问题 这是我的课 import java.util.Collection; import org.springframework.boot.actuate.endpoint.PublicMetrics; import or

我想监控一些应用程序,我正在使用普罗米修斯。它在某些应用程序中运行良好,但当我尝试在另一个应用程序中实现它时,我遇到了一些问题。 它说:

构造函数ServletRegistrationBean(MetricsServlet,String)未定义

什么会导致此问题以及如何解决此问题

这是我的课

import java.util.Collection;

import org.springframework.boot.actuate.endpoint.PublicMetrics;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import io.prometheus.client.exporter.MetricsServlet;
import io.prometheus.client.hotspot.DefaultExports;
import io.prometheus.client.spring.boot.SpringBootMetricsCollector;

@Configuration
public class MonitoringConfig {

    @Bean
    SpringBootMetricsCollector springBootMetricsCollector(Collection<PublicMetrics> publicMetrics) {

        SpringBootMetricsCollector springBootMetricsCollector = new SpringBootMetricsCollector(publicMetrics);
        springBootMetricsCollector.register();

        return springBootMetricsCollector;
    }

    @Bean
    public ServletRegistrationBean servletRegistrationBean() {
        DefaultExports.initialize();
        return new ServletRegistrationBean(new MetricsServlet(), "/prometheus");
    }

}
import java.util.Collection;
导入org.springframework.boot.actuate.endpoint.PublicMetrics;
导入org.springframework.boot.web.servlet.ServletRegistrationBean;
导入org.springframework.context.annotation.Bean;
导入org.springframework.context.annotation.Configuration;
导入io.prometheus.client.exporter.MetricsServlet;
导入io.prometheus.client.hotspot.DefaultExports;
导入io.prometheus.client.spring.boot.SpringBootMetricsCollector;
@配置
公共类监视配置{
@豆子
SpringBootMetricsCollector SpringBootMetricsCollector(集合publicMetrics){
SpringBootMetricsCollector SpringBootMetricsCollector=新的SpringBootMetricsCollector(publicMetrics);
springBootMetricsCollector.register();
返回springBootMetricsCollector;
}
@豆子
公共ServletRegistrationBean ServletRegistrationBean(){
DefaultExports.initialize();
返回新的ServletRegistrationBean(newMetricsServlet(),“/prometheus”);
}
}
从属关系:

<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-actuator -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-actuator</artifactId>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.moelholm/prometheus-spring-boot-starter -->
    <dependency>
        <groupId>com.moelholm</groupId>
        <artifactId>prometheus-spring-boot-starter</artifactId>
        <version>1.0.2</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient -->
    <dependency>
        <groupId>io.prometheus</groupId>
        <artifactId>simpleclient</artifactId>
        <version>0.0.25</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient_hotspot -->
    <dependency>
        <groupId>io.prometheus</groupId>
        <artifactId>simpleclient_hotspot</artifactId>
        <version>0.0.25</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient_spring_boot -->
    <dependency>
        <groupId>io.prometheus</groupId>
        <artifactId>simpleclient_spring_boot</artifactId>
        <version>0.0.25</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/io.prometheus/simpleclient_servlet -->
    <dependency>
        <groupId>io.prometheus</groupId>
        <artifactId>simpleclient_servlet</artifactId>
        <version>0.0.25</version>
    </dependency>

org.springframework.boot
弹簧靴执行器
com.moelholm
普罗米修斯弹簧靴起动器
1.0.2
伊奥·普罗米修斯
简单的
0.0.25
伊奥·普罗米修斯
simpleclient\u热点
0.0.25
伊奥·普罗米修斯
simpleclient\u弹簧\u靴
0.0.25
伊奥·普罗米修斯
simpleclient_servlet
0.0.25
在某些应用程序中,它可以工作,但在其中一个应用程序中,我使用了以下内容:


构造函数ServletRegistrationBean(MetricsServlet,String)未定义MetricsServlet应实现javax.servlet.servlet。确保在项目/类路径中有该类(即javax.servlet.servlet)。 包含此类的库的maven依赖项为:

<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.5</version>
    <scope>provided</scope>
</dependency>

javax.servlet
servlet api
2.5
假如

现在没有错误,但我仍然无法获取指标,当我访问localhost:8787/prometheus时,我无法找到。那么,maven依赖项是否解决了您的问题(即构造函数ServletRegistrationBean(MetricsServlet,String)未定义)?是的,但我仍然无法获取指标。我理解。如果是这样,我认为应该解决一个新问题。我也会尽力帮你解决这个问题(如果可以的话)好的,谢谢:)