21

I am using spring boot 2.1.4.RELEASE and currently trying to access http://localhost:8080/actuator but i am getting 404 not found. I am not sure what am i doing wrong here. Below is my pom dependencies-

 <?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>

properties file config

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

when i run the application i do see this in console

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'
Jon Abraham
  • 851
  • 3
  • 14
  • 27

15 Answers15

31

Please check if you have configured server.servlet.contextPath=/myendpoint

If you have done like this please try localhost:8080/{server.servlet.contextPath}/actuator

RAJKUMAR NAGARETHINAM
  • 1,408
  • 1
  • 15
  • 26
  • yes i have configured server.servlet.context-path=/myendpoint but when i tried accessing - localhost:8080/myendpoint/actuator via browser or postman i am getting 401 unauthorized istead of 404 not found. – Jon Abraham Apr 27 '19 at 15:13
  • My app uses application.yml instead of application.properties and I found the context path setting as server: context-path: /some/path – Bruno Negrão Zica Sep 03 '20 at 03:31
11

Certain actuator endpoints are disabled, and have to be enabled before you can use them. I was trying to access /actuator/beans, which turns out to be just such an endpoint. According to the docs, all you need is to enable them in your application.properties file:

management.endpoints.web.exposure.include=health,info,beans
teuber789
  • 1,527
  • 16
  • 28
  • 1
    he already has that line in his properties: management.endpoints.web.exposure.include=* – jodoro Jan 21 '22 at 18:35
  • although this wasn't an answer for OP's Question specifically (as jodoro correctly pointed out), this can help other similar scenarios where this property is not yet in place. (and `management.endpoints.web.exposure.include=*` enables _all_ Actuator endpoints) – cellepo Apr 12 '23 at 02:11
10

Spring boot Actuator URL changing through SpringBoot Releases, Initially we can Access Actuator URL with https://localhost:8080/actuator

in early milestone versions of springboot 2.0.0 the URL is https://localhost:8080/application

Now current springboot version it can be access through https://localhost:8080/actuator

Narendar Reddy M
  • 1,499
  • 1
  • 11
  • 18
  • i tried to access https://localhost:8080/actuator instead of http://localhost:8080/actuator and now i am seeing java.lang.IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens. I believe this is occuring since my client endpoint is not https configured. – Jon Abraham Apr 27 '19 at 15:19
  • 7
    Dear @JonAbraham You have mentioned both as localhost:8080/actuator what is the difference? – Narendar Reddy M Apr 28 '19 at 06:09
8

I'm using a spring boot. I got this simple message from spring boot.

Spring Boot /actuator returns 404 not found

here is my application.yml file.

server:
  port: 6150
  servlet:
    context-path: /


management:
  server:
    port: 6150
  endpoints:
    web:
      base-path: /actuator
      exposure:
        include: "*"

and then:

http://localhost:6150/actuator

I know this question is quit old and some situation(condition) is different.
I hopefully someone save their time.

daim tak
  • 81
  • 1
  • 1
7

As per above answers Try

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

but if it show error so there would be these possible reason is that you not include dependency in you pom.xml

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
Abhinav Sahu
  • 183
  • 2
  • 9
5

I had the same 404 error, even after exactly following Spring documentation. What finally worked for me was deleting actuator dependency and the jar, and adding it again, with a mvn clean install. It worked :)

Manisha
  • 51
  • 1
  • 3
3

I had a similar problem, but my issue was that the following application property was set in my project:

management:
  endpoints:
    web:
      base-path: /

Which meant that the actual endpoint for something like: http://localhost:8080/actuator/beans

was in fact: http://localhost:8080/beans

Joseph Cass
  • 119
  • 1
  • 3
2

I think there is a context path /myendpoint in your application.

Please try with this endpoint http://localhost:8080/myendpoint/actuator

GnanaJeyam
  • 2,780
  • 16
  • 27
  • I tried this and now i am getting 401 unauthorized. – Jon Abraham Apr 27 '19 at 15:18
  • can you share full pem.xml file@JonAbraham – RAJKUMAR NAGARETHINAM Apr 27 '19 at 17:08
  • @RAJKUMAR i have posted full POM.xml file for your review – Jon Abraham Apr 27 '19 at 20:14
  • I see where the problem is in the console after i added actuator dependency i don't see these type of logs -s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator/auditevents],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object – Jon Abraham Apr 27 '19 at 22:43
  • Just an update i was able to see response at - http://localhost:8080/actuator. I simply deleted the actuator jar and did maven clean install. After that i was able to see response – Jon Abraham Apr 28 '19 at 03:26
1

This was the first result when I googled a similar issue I was having. Unfortunately none of the solutions above worked for me but another source mentioned that I needed to set the management port:

management.server.port=8080

Which allows me to hit

 http://localhost:8080/actuator/
nash
  • 3,020
  • 6
  • 38
  • 53
1

Because you misunderstand.

Exposed endpoints are in two ways, please read carefully in the docs. One is exposed to JMX, while the other is exposed to WEB.

enter image description here

Obviously, if you enable the beans endpoint, it only expose to JMX.

JoseLuis
  • 81
  • 1
  • 8
1

I solved for spring 2.6.x with a bean

    @Bean
    public HttpTraceRepository httpTraceRepository() {
        return new InMemoryHttpTraceRepository();
    }

as aware for the project instructions on the link: Spring-Boot-2.2.0-M3-Release-Notes

0

It was a version conflict for me which was why the actuator endpoints were not exposed. I removed the version from the pom file for spring-boot-starter-actuator to make it work

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-actuator</artifactId>
    <!--<version>1.5.6.RELEASE</version>-->
</dependency>
Vasudev
  • 803
  • 1
  • 7
  • 16
0

For my project, the problem could be resolved by adding the maven-clean-plugin. In the project, I am using the spring-boot-maven-plugin like this:

<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
  <outputDirectory>./out</outputDirectory>
</configuration>

I was not able to view any indicator until using the maven-clean-plugin:

<artifactId>maven-clean-plugin</artifactId>
<configuration>
  <filesets>
    <fileset>
      <directory>./out</directory>
    </fileset>
  </filesets>
</configuration>
rschmidt13
  • 349
  • 3
  • 3
0

Please check your log which genereted by ide, you sholud not get something like that in you init log. Exposing 13 endpoint(s) beneath base path ''(if you are getting the same please addd this like to you application.properties management.endpoints.web.base-path=/actuator ) I am talking about log console where you can check as this

enter image description here

basically, add this line management.endpoints.web.base-path=/actuator in your application application.prperties and try, since it is mentioned in the tutorial, that when the management base path is set to /, the discovery endpoint is disabled.

Community
  • 1
  • 1
-1

If you are getting 401 unauthorised then you should add roll "ACTUATOR" in your token, then only you will be able to hit /actuator endpoints of your application.

Connell.O'Donnell
  • 3,603
  • 11
  • 27
  • 61