当前位置:   article > 正文

解决 Spring Cloud 的服务应用配置 context-path 后 Spring Boot Admin 监控不到信息的问题_management.server.servlet.context-path

management.server.servlet.context-path

在上篇文章中,讲解了 Spring Cloud 服务使用 Spring Boot Admin 监控的搭建,但是我在做公司的传统项目改造成微服务架构的过程中,在搭建 Spring Boot Admin 的时候,遇到了一个坑,有个服务配置了 context-path 这个属性,导致 Spring Boot Admin 一直获取不到这个服务的端点信息(当时我对 Spring Boot Admin 的使用、原理还不熟悉),现在通过 Spring Boot Admin 的部分源码分析来看看怎么解决这个问题,记录一下我踩到的坑。

(一)首先,我们看下服务配置了 context-path 属性后,不做其他配置,Spring Boot Admin 是什么样子。

拿之前文章里写的服务 spring-demo-service-feign 做例子

修改 spring-demo-service-feign 的配置文件,添加 context-path 的配置如下:

  1. eureka:
  2. client:
  3. serviceUrl:
  4. defaultZone: http://localhost:8761/eureka/
  5. server:
  6. port: 8382
  7. servlet:
  8. context-path: /gateway
  9. spring:
  10. application:
  11. name: spring-demo-service-feign
  12. feign:
  13. hystrix:
  14. enabled: true
  15. # Ribbon 的负载均衡策略
  16. spring-demo-service:
  17. ribbon:
  18. NFLoadBalancerRuleClassName: com.netflix.loadbalancer.BestAvailableRule
  19. management:
  20. endpoints:
  21. web:
  22. exposure:
  23. include: '*'
  24. endpoint:
  25. health:
  26. show-details: ALWAYS
  27. info:
  28. version: 1.0.0

其他的不用配置,以此启动 eureka serverspring-demo-servicespring-demo-service-feignspringboot-admin 服务

访问 http://localhost:8788/,登录后

可以看到,spring-demo-service-feign 的服务是 DOWN 的状态,点击 spring-demo-service-feign 查看

什么信息都没有,这让我很纳闷,当时不知道是 context-path 造成的,下面先说下解决方案,在通过源码简单分析一下。

(二)对上面的问题,我们可以通过再加几个属性配置来解决

修改 spring-demo-service-feign 的配置文件:

  1. eureka:
  2. client:
  3. serviceUrl:
  4. defaultZone: http://localhost:8761/eureka/
  5. # 如果项目配置有 server.servlet.context-path 属性,想要被 spring boot admin 监控,就要配置以下属性
  6. instanc
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/你好赵伟/article/detail/856537
推荐阅读
相关标签
  

闽ICP备14008679号