Spring actuator endpoints does not work on the application port

Viewed 3445

I am trying to enable the actuator endpoints on the same port as the application port (specified in the application.properties file by the server.port=8080) but for some reason, it does not work. When I run the application, I can get back the response from the application but not from the actuator endpoints. I can see the logs mention the endpoints being exposed beneath base path '/actuator' as shown in the screenshot below. But when I try to hit the actuator URL, it gives a 404.

URL, not working:

However, if I specify a separate port in application.properties for the actuator endpoints with the property (management.server.port=9000) then it works fine.

URL, that's working:

The only difference is about the port number but from what I read in the spring documentation, the actuator endpoints should by default be enabled on the application port if we don't specify the management.server.port. Can someone please explain what am I missing here?enter image description here PS: The application run logs are exactly the same with or without specifying the management.server.port, hence, this one screenshot is without specifying the management port. Also, I tried giving the same port number for both the property (server.port and management.server.port) but the same problem occurs. The application works on that port but the actuator endpoints do not. I am using the spring-boot version 2.0.6

These are the contents of my application.properties file:

camel.springboot.main-run-controller=true
camel.springboot.name=AppName
camel.rest.data-format-property.prettyPrint=false
camel.component.servlet.mapping.context-path=/*

server.port=8080
management.server.port=9000

management.endpoint.health.show-details=always
management.endpoint.beans.enabled=true

logging.level.org.springframework = INFO
logging.level.org.apache.camel.spring.boot = INFO
logging.level.org.apache.camel.impl = DEBUG

Here are the dependencies in pom.xml:

<dependencies>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-spring-boot-starter</artifactId>
        </dependency>

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

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.camel</groupId>
            <artifactId>camel-servlet-starter</artifactId>
        </dependency>
</dependencies>
4 Answers

Regarding the Spring Boot Actuator documentation

Exposing management endpoints by using the default HTTP port is a sensible choice for cloud-based deployments. If, however, your application runs inside your own data center, you may prefer to expose endpoints by using a different HTTP port.

it serves the Actuator using the default HTTP port (which is 8080). I did a quick check and could confirm this with Spring Boot 2.1.X and 2.2.X.

Try to remove the management.port from your config and if this does not work then the problem might come from an additional (custom) configuration in your application.

Remove management.server.port=9000, this property overrides server.port=8080.

Please set the below in application.properties file

management.endpoints.enabled-by-default=true 

management.endpoints.web.exposure.include=*  

I had the same problem, what was causing this for me was a conflict between the context I declared for camel and the one being used for spring actuator.

So, at application.yml I had these 3 contexts:

server: servlet: context-path: myservercontext/v1
camel: component: servlet: mapping: contextPath: /*
management: endpoints: web: base-path: "/"

I think after the request hits the server it gets lost on this ambiguity so i solved it by changing these contexts to:

server: servlet: context-path: myservercontext/v1
camel: component: servlet: mapping: contextPath: /camel/*
management: endpoints: web: base-path: "/"

This worked out nicely for me since all my resources where grouped under "/camel" anyway but as I tested I found out this also works:

server: servlet: context-path: myservercontext
camel: component: servlet: mapping: contextPath: /v1/*
management: endpoints: web: base-path: "/"

Just note that in this last scenario the health route won't be under "v1".

I would never have figured out the cause of this problem if it wasn't for this question, even if it wasn't solved yet, so I thank you a lot for posting this and hope my solution will manage to help others ^^

Related