springCloud Gateway集成注意事项

本文介绍了Spring Cloud Gateway的集成步骤,强调了不应引入web依赖,并展示了如何通过@EnableDiscoveryClient注解启用Gateway。同时,详细说明了在YML和properties文件中配置路由规则的细节,包括ID、URI、断言和过滤器的设置,提醒注意配置文件的缩进问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

集成Gateway总体来说是比较简单,但有些细节需要注意,404警告~~

1.Gateway项目不能引入web依赖

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

2.Gateway功能开启需要在启动类加入注解

@SpringBootApplication
@EnableDiscoveryClient   //启用Gateway
public class TestApplication {
    public static void main(String[] args) {
        SpringApplication.run(TestApplication .class, args);
    }
}

3.Gateway配置如果是在配置文件

application.yml

spring:
  cloud:
    gateway:
      routes:
        - id: admin-service
          uri: http://localhost:20912
          predicates:
            - Path=/api/admin/**
          filters:
            - StripPrefix=2

application.properties

spring.cloud.gateway.routes[0].id=admin-service
spring.cloud.gateway.routes[0].uri=http://localhost:20912
spring.cloud.gateway.routes[0].predicates[0]=Path=/api/admin/**
spring.cloud.gateway.routes[0].filters[0]=StripPrefix=2

需注意配置的拼写,采用yml的话更需要检查缩进

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值