微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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>

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐