nacos gateway 呼叫服務報錯503 Server unavailable

iiiiiiiivan發表於2024-10-09

環境

springboot3 jdk17

依賴

 <dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-starter-bootstrap</artifactId>
 </dependency>
 <dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-loadbalancer</artifactId>
 </dependency>
 <dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-starter-gateway</artifactId>
 </dependency>
 <dependency>
     <groupId>com.alibaba.cloud</groupId>
     <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
 </dependency>
 <dependency>
     <groupId>com.alibaba.cloud</groupId>
     <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>

nacos配置

spring:
  cloud:
    gateway:
      globalcors:
        add-to-simple-url-handler-mapping: true
        corsConfigurations:
          '[/**]':
            allowedHeaders: "*"
            allowedOrigins: "*"
            allowedMethods:
              - GET
              - POST
              - DELETE
              - PUT
              - OPTION
      routes:
        # 平臺管理
        - id: user
          uri: lb://black-news-user
          predicates:
            - Path=/user/**
          filters:
            - StripPrefix= 1

請求報錯

{
    "timestamp": "2024-10-09T02:46:28.582+00:00",
    "path": "/user/api/v1/login/login_auth",
    "status": 503,
    "error": "Service Unavailable",
    "requestId": "5cbc278"
}

就是需要加

<dependency>
     <groupId>org.springframework.cloud</groupId>
     <artifactId>spring-cloud-loadbalancer</artifactId>
</dependency>

相關文章