如何让Actuator路径不受Servlet context-path影响?
解决方案
要让Actuator端点绕过应用的context-path,直接通过根路径下的/actuator访问,只需在配置中添加management.server.servlet.context-path并设为空字符串即可,具体配置如下:
server: servlet: context-path: /product-management management: server: servlet: context-path: "" # 单独指定Actuator的上下文路径,不继承应用的context-path endpoints: web: exposure: include: health,info,metrics base-path: /actuator endpoint: health: show-details: always info: enabled: true
配置说明
management.server.servlet.context-path是Spring Boot专门用于配置Actuator端点的Servlet上下文路径,默认会继承server.servlet.context-path的值;将其设为空字符串后,Actuator的路径就从根路径开始。- 结合原有的
management.endpoints.web.base-path: /actuator,最终Actuator的访问路径就变成了http://localhost:8080/actuator/health,完全避开了应用的/product-management前缀。 - 应用的业务接口依然保持
/product-management前缀的访问路径,无需修改Kubernetes中已配置的就绪/存活探针URL。
内容的提问来源于stack exchange,提问作者DK93
相关产品推荐
相关产品推荐

