简体   繁体   中英

Spring boot actuator not start with the port specified

I am trying to enable the actuator on an existing Spring Boot 2 application, which I thought would be straightforward as I have done few times for the application I created from scratch. However, somehow tomcat (as default server) not startup with the actuator port configured in the properties, when the application starts.

Here are snippets of the config and pom

server:
  port: 8085
management:
  port: 9085


        <spring-boot.version>2.3.5.RELEASE</spring-boot.version>


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

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

In the log of application startup, I can see the server port has been bound to the application but didn't see the actuator one specified in the properties.

18:32:08.435 [main] INFO  o.a.c.h.Http11NioProtocol - Starting ProtocolHandler ["http-nio-8085"]
18:32:08.524 [main] INFO  o.s.b.w.e.t.TomcatWebServer - Tomcat started on port(s): 8085 (http) with context path ''

I would expect to see a port binding like the log below right after the one above.

2021-01-20 17:01:35.636  INFO 20044 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 9085 (http)

I have checked the port has not been used by any other application. Did I miss anything else?

From your posting info, you should add some setting to enable endpoints. I give a sample. please try. By another word, management.port is used in spring boot 1.x.

In simple way, you just enable all endpoints and expose all. for security reason, you should make management.endpoints.enabled-by-default to false. then enable endpoint you want to expose.


management:
  server:
    port: 9085
  endpoints:
    enabled-by-default: true
    web:
#      base-path: /mgmt          # you can change /actuator to another name
      exposure:
        include: "*"
#  endpoint:
#    refresh:
#      enabled: true
#    loggers:
#      enabled: true
#    env:
#      enabled: true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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