Spring Boot / actuator返回404找不到

时间:2019-04-27 04:13:13

标签: spring spring-boot spring-boot-actuator

我正在使用Spring Boot 2.1.4.RELEASE,当前正在尝试访问http://localhost:8080/actuator,但找不到404。我不确定我在这里做错了什么。以下是我的pom依赖项-

 <?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.dir</groupId>
    <artifactId>api</artifactId>
    <version>2.4.0</version>
    <packaging>jar</packaging>

    <name>Search</name>
    <description>Search</description>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.4.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>

    <distributionManagement>
        <repository>
            <id>Releases</id>
            <name>repo1.releases</name>
            <url>http://www.something.com</url>
        </repository>
        <snapshotRepository>
            <id>Snapshots</id>
            <name>repo1.com</name>
            <url>http://repo1.com/artifactory/Snapshots</url>
        </snapshotRepository>
    </distributionManagement>


    <properties>
        <!--These two should be in all ParentPOMs -->
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <!-- Keep this version in sync with the pom's version ignoring "-SNAPSHOT" -->
        <applicationVersion>1.0.0</applicationVersion>
        <elasticsearch.version>5.2.0</elasticsearch.version>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-configuration-processor</artifactId>
            <optional>true</optional>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.4.0</version>
        </dependency>

        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.4.0</version>
        </dependency>


        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webflux</artifactId>
        </dependency>

        <dependency>
            <groupId>io.swagger</groupId>
            <artifactId>swagger-annotations</artifactId>
            <version>1.5.7</version>
        </dependency>



        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.8.0</version>
        </dependency>

        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>x-pack-transport</artifactId>
            <version>5.2.1</version>
        </dependency>

        <dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>transport</artifactId>
            <version>5.2.0</version>
        </dependency>

        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>5.2.0</version>
        </dependency>

        <dependency>
            <groupId>apache-lang</groupId>
            <artifactId>commons-lang</artifactId>
            <version>2.1</version>
        </dependency>



        <dependency>
            <groupId>io.jsonwebtoken</groupId>
            <artifactId>jjwt</artifactId>
            <version>0.7.0</version>
        </dependency>

        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.17</version>
        </dependency>

        <!-- Spring boot actuator to expose metrics endpoint -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <!-- Micormeter core dependecy  -->
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-core</artifactId>
        </dependency>
        <!-- Micrometer Prometheus registry  -->
        <dependency>
            <groupId>io.micrometer</groupId>
            <artifactId>micrometer-registry-prometheus</artifactId>
        </dependency>




    </dependencies>


    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-deploy-plugin</artifactId>
                <version>2.8.2</version>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <configuration>
                    <environmentVariables>
                        <version>9.9.9</version>
                        <basePath>http://sample-basepath.com</basePath>

                    </environmentVariables>
                </configuration>
            </plugin>
        </plugins>

        <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
        </resources>

    </build>


</project>

属性文件配置

management.endpoint.metrics.enabled=true
management.endpoints.web.exposure.include=*
management.endpoint.prometheus.enabled=true
management.metrics.export.prometheus.enabled=true
management.endpoint.health.show-details=always
management.endpoint.beans.enabled=true

当我运行应用程序时,我确实在控制台中看到了

2019-04-27 00:04:25.406  INFO 32522 --- [           main] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 16 endpoint(s) beneath base path '/actuator'
2019-04-27 00:04:25.534  INFO 32522 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path '/myendpoint'

8 个答案:

答案 0 :(得分:2)

请检查您是否已配置 server.servlet.contextPath = / myendpoint

如果您这样做,请尝试localhost:8080 / {server.servlet.contextPath} / actuator

答案 1 :(得分:2)

即使完全遵循 Spring 文档,我也遇到了相同的 404 错误。最终对我有用的是删除执行器依赖项和 jar,然后通过 mvn 全新安装再次添加它。它奏效了:)

答案 2 :(得分:0)

我认为您的应用程序中有一个上下文路径 / myendpoint

请尝试使用此端点 http://localhost:8080/myendpoint/actuator

答案 3 :(得分:0)

Spring Boot Actuator URL通过SpringBoot版本进行更改, 最初,我们可以使用https://localhost:8080/actuator

访问执行器URL

在springboot 2.0.0的早期里程碑版本中,URL为https://localhost:8080/application

现在是最新的springboot版本,可以通过https://localhost:8080/actuator

访问

答案 4 :(得分:0)

按照上述答案尝试

 http://localhost:8080/<server.servlet.context-path>/actuator/

但是如果它显示错误,那么可能是由于您没有在pom.xml中包含依赖项

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

答案 5 :(得分:0)

某些执行器端点已禁用,必须先禁用才能使用它们。我试图访问 /actuator/beans,结果证明它就是这样一个端点。根据 [the docs][1],您只需将它们包含在您的 application.properties 文件中:

management.endpoints.web.exposure.include=health,info,beans

答案 6 :(得分:0)

对我来说这是一个版本冲突,这就是执行器端点没有公开的原因。我从 spring-boot-starter-actuator 的 pom 文件中删除了版本以使其工作

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <!--<version>1.5.6.RELEASE</version>-->
</dependency>

答案 7 :(得分:-1)

如果您得到 401 未授权,那么您应该在您的令牌中添加滚动“ACTUATOR”,然后只有您才能点击应用程序的 /actuator 端点。