java - Spring 执行器端点在应用程序端口上不起作用

标签 java spring spring-boot port spring-boot-actuator

我试图在与应用程序端口(在 application.properties 文件中由 server.port=8080 指定)相同的端口上启用执行器端点,但由于某种原因,它不起作用。当我运行应用程序时,我可以从应用程序获取响应,但不能从执行器端点获取响应。我可以看到日志提到了暴露在基本路径“/actuator”下的端点,如下面的屏幕截图所示。但是当我尝试点击执行器 URL 时,它给出了 404。

网址,不工作 :

  • http://localhost : 8080 /执行器
  • http://localhost : 8080 /执行器/健康
  • http://localhost : 8080 /执行器/信息

  • 但是,如果我在 application.properties 中为具有属性 (management.server.port=9000) 的执行器端点指定单独的端口,则它可以正常工作。

    网址,即 工作 :
  • http://localhost : 9000 /执行器
  • http://localhost : 9000 /执行器/健康
  • http://localhost : 9000 /执行器/信息

  • 唯一的区别在于端口号,但从我在 spring 文档中读到的内容来看,如果我们不指定 management.server.port,则默认情况下应该在应用程序端口上启用执行器端点。
    有人可以解释一下我在这里缺少什么吗? enter image description here
    PS:应用运行日志无论是否指定 management.server.port 都是一样的,所以这个截图是没有指定管理端口的。
    此外,我尝试为两个属性(server.port 和 management.server.port)提供相同的端口号,但发生了同样的问题。应用程序在该端口上工作,但执行器端点不工作。
    我使用的是 spring-boot 版本 2.0.6

    这些是我的 application.properties 文件的内容:
    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
    

    以下是 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>
    

    最佳答案

    关于 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.



    它使用默认的 HTTP 端口(即 8080)为执行器提供服务。我做了一个快速检查,可以用 Spring Boot 2.1.X 和 2.2.X 确认这一点。

    尝试删除 management.port来自您的配置,如果这不起作用,那么问题可能来自您的应用程序中的其他(自定义)配置。

    关于java - Spring 执行器端点在应用程序端口上不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60673803/

    相关文章:

    java - 有没有办法在过滤器内创建 Cookie 并将其添加到响应中?

    Java 解析 Json 与具有不同对象类型的数组(Gson 或 Jackson 等)

    mysql - 运行 spring boot jar 文件时出错(创建名称为 'dataSource' 的 bean 时出错)

    java - 将 xml 发布到 spring REST 端点不会被解码到相关的 Java 对象中

    java - Spring-Boot @Scheduled Cron 表达式在两个任务之间稍微延迟?

    Java 如何清除kidCache?

    java - 需要字符串缓冲区帮助

    java - 我在哪里可以在 Spring 3.1 中指定 Jackson SerializationConfig.Feature 设置

    java - 由于 Boxfuse Dev VM 上的 SSL 错误,Spring Boot 应用程序未启动

    java - 在 Java 中,Azure applicationinsights 启动程序依赖项与 Spring Boot 3.x.x 不兼容