其他分享
首页 > 其他分享> > BUG记录:springcloud配置网关后,访问接口返回404

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>

 

标签:网关,springcloud,product,404,88,api,spring,cloud
来源: https://www.cnblogs.com/teemo-zhao/p/16469400.html