1
创建,使用initilizer,Group:com.atguigu.gulimall,Artifact: gulimall-gateway,package:com.atguigu.gulimall.gateway。 搜索gateway选中。
pom.xml里加上common依赖, 修改jdk版本
在启动类中添加注解@EeableDiscoveryClient
配置nacos注册中心地址
spring.cloud.nacos.discovery.server-addr=127.0.0.1:8848
spring.application.name=gulimall-gateway
server.port=88
bootstrap.properties 填写配置中心地址
spring.application.name=gulimall-gateway
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
spring.cloud.nacos.config.namespace=ab66aff2-0bd5-4f80-8a68-760d6ff7d96d
nacos里创建命名空间gateway,然后在命名空间里创建文件guilmall-gateway.yml
spring:
application:
name: gulimall-gateway
在主类中屏蔽数据源
在项目里创建application.yml
spring:
cloud:
gateway:
routes:
- id: after_route
uri: https://www.xiaomi.com
predicates:
- Query=url,xiaomi
# 若参数等于断言 则跳转到指定的uri