spring-cloud-consul:设置servlet context-path 导致的 Consul 健康检查失败
配置文件
server:
port: 9021
servlet:
context-path: /config
去掉 server.servlet.context-path=/config 后
server:
port: 9021
# servlet:
# context-path: /config
原因及解决办法
原因:consul对微服务的健康检查路径是固定的。默认为 /actuator/health,没有自动加上 servlet.context-path中设置的 /config 作为前缀(应该算是一个小缺陷)。
也就是说:/config/actuator/health 才是正确的!
解决办法:
修改 consul 的 health-check-path:
spring:
cloud:
consul:
discovery:
health-check-path: ${server.servlet.context-path}/actuator/health
效果:
PS:
似乎 nacos 也是有同样的问题。可以用同样的思路解决
spring:
cloud:
nacos:
discovery:
metadata:
management:
context-path: ${server.servlet.context-path}/actuator