sppringcloud應用啟動 訪問gateway無法path無法路由到目標應用,404


 

 

 

當訪問http://localhost:8080/nacos-provider-auth/test 時報404錯誤

這里處理方法有兩種

1.在目標應用添加 context-path

server:
  port: 8081
  servlet:
    context-path: "/nacos-provider-auth"

2.去掉訪問前綴 StripPrefix, 例如,StripPrefix=1請求/nacos-provider-auth/test,去除掉前面一個前綴之后,最后轉發到目標服務的路徑為/test

spring:
  application:
    name: nacos-provider-gateway
  cloud:
    nacos:
      discovery:
        server-addr: 127.0.0.1:8848
    gateway:
      discovery:
        locator:
          lower-case-service-id: true #將請求路徑上的服務名配置為小寫(因為服務注冊的時候,向注冊中心注冊時將服務名轉成大寫的了,比如以/service-hi/*的請求路徑被路由轉發到服務名為service-hi的服務上
          enabled: false #表明gateway開啟服務注冊和發現的功能,並且spring cloud gateway自動根據服務發現為每一個服務創建了一個router,# 這個router將以服務名開頭的請求路徑轉發到對應的服務
      routes:
      - id: nacos-provider-auth
        uri: lb://nacos-provider-auth
        order: -1
        predicates:
        - Path=/nacos-provider-auth/**
        filters:
        - StripPrefix=1

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM