BUG记录:springcloud配置网关后,访问接口返回404

项目结构:前端端口8001,访问后端网关端口88,网关配置好跨域问题后,再将请求转发到相应的业务接口。但是配置好了之后,前端访问88端口返回404

网关的application.yml

spring:
  cloud:
    nacos:
    discovery:
      server-addr: 124.221.226.193:8848
    gateway:
      routes:
        - id: product_route
          uri: lb://bearmall-product
          predicates:
            - Path=/api/product/**
          filters:
            - RewritePath=/api/(?<segment>.*),/$\{segment}

        - id: admin_route
          uri: lb://renren-fast
          predicates:
            - Path=/api/**
          filters:
            - RewritePath=/api/(?<segment>.*),/renren-fast/$\{segment}



  application:
    name: bearmall-gateway

server:
  port: 88

 

问题解决:高版本的springboot,在pom文件里需要添加 spring-cloud-starter-loadbalancer 依赖

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

 

posted @ 2022-07-12 11:22  Teemo_zhao  阅读(1124)  评论(0编辑  收藏  举报