gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 22:49:11 25 4
gpt4 key购买 nike

我有一个使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com