1. 创建module 引入 Gateway依赖
添加Nacos注册发现注解,排除common中的mybatis有关的
@EnableDiscoveryClient
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class GulimallGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GulimallGatewayApplication.class, args);
}
}
2. 先进与配置中心的配置
创建bootstrap.properties 文件进行配置中心的配置
# Nacos 中创建的properties 名字和此对应 gulimall-coupon.properties
spring.application.name=gulimall-gateway
#Nacos地址
spring.cloud.nacos.config.server-addr=127.0.0.1:8848
#Nacos中的命名空间,可以按 不同服务分命名空间,按不同的时间段分命名空间
spring.cloud.nacos.config.namespace=3f0e7b58-9895-48ba-ac41-9d5700f345ed
3. 创建application.yml 配置注册中心与网关的配置
注意网关的跳转只能是本IP的跳转,默认端口也不会改变,会加上原来的参数
spring:
cloud:
gateway:
routes:
- id: query_route
uri: http://localhost:8080/
predicates:
- Query=green
nacos:
discovery:
server-addr: 127.0.0.1:8848
application:
name: gulimall-gateway
server:
port: 88