使用consul+gateway時,gateway轉發報錯

引入的consul服務依賴:

   <!--consul依賴-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-consul-discovery</artifactId>
            <version>2.2.2.RELEASE</version>
        </dependency>

 

路由信息:

報錯的信息如下:

 

consul的配置:

 

spring:
  application:
    name: blog-admin
  cloud:
    #consul server地址
    consul:
      host: localhost
      port: 8500    #consul默認端口
      # 健康檢查 一定要配置 結合 spring-boot-starter-actuator 使用
      discovery:
        health-check-path: /actuator/health
        health-check-interval: 10s
      ribbon:  ## 配合hello-world.ribbon.listOfServers=192.168.26.183:8777使用解決 Load balancer does not have available server for client:blog-picture問題
        enabled: false

    查看consul頁面:

可以看到consul服務都註冊上去了,但是爲什麼還是gateway轉發不來呢,網關的配置我就不貼出來了,用的動態網關,有點多,可以私信我

 

其實服務是註冊上去了,但是可以看到

 

 

有個很顯眼的x,這個是什麼意思呢,這個表示你的服務健康檢查是不通過的,你可以查看consul啓動界面的信息

對比一下,沒有x的說明服務是健康的,其實在配置文件中我已經說明了

查看引入的jar,發現是我沒有引入這個依賴:

添加依賴:

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
            <version>2.2.2.RELEASE</version>
        </dependency>

再次啓動項目,查看consul

可以看到都是健康的實例了,請求接口:

成功了!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章