java - 如何根据应用程序属性制作 Spring Boot 2 执行器路径?

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

我有一个使用 Spring Boot 2 的微服务应用程序,它使用我自己的库通过执行器功能将新端点传播到自身 - 我自己的执行器实现了 MvcEndpoint 接口(interface),并包含“路径”变量,该变量从应用程序获取真正的 API 映射使用此库的微服务的 .yml。

但是在我将库重新编码为 Spring Boot 2 后,我遇到了一个问题 - @Endpoint 注释上的 id 属性仅包含常量值(与每个注释属性一样),我还没有找到将执行器端点的 API 路径更改为“/api/v1/my-service/my-actuator-endpoint”之类的方法。

我尝试将其写入微服务的 application.yml 中:

endpoints:
  my-actuator-endpoint:
    path: /api/v1/my-service/my-actuator-endpoint

但是这个端点仍然只能从/my-actuator-endpoint 访问,这意味着只能通过它的 id 访问。

如何使其可以通过/api/v1/my-service/my-actuator-endpoint 等自定义路径访问,该路径将在 application.yml 中配置?

最佳答案

问题已解决,需要将此属性添加到 application.yml:

management:
  endpoints:
    web:
      path-mapping:
        my-actuator-endpoint: api/v1/my-service/my-actuator-endpoint

关于java - 如何根据应用程序属性制作 Spring Boot 2 执行器路径?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58463744/

相关文章:

java - JPA + MySQL - 数据库生成的列值

Java ByteBuffer.wrap(byte[]),如果 byte[] 按小尾数排序,尾数会发生什么变化

java - 无法提取响应 : no suitable HttpMessageConverter found for response type class and content type [text/html]

java - 应用程序上下文是否总是需要在服务器上加载 war 文件

spring-boot - 如何使用 Axon Server 向上转换事件?

java - 由于 ClosedChannelException (DFSOutputStream.checkClosed) 而导致的 Spark 作业失败

java - Spring调度程序关闭错误

java - Fongo 2.1.0 不适用于 Mongo Java 驱动程序 3.2.8

java - Lombok 不生成 RequiredArgsConstructor 和 AllArgsConstructor

c# - 如何将C#代码转换为Kotlin的Json库