-
1.创建项目:test-gateway-2.1
-
2.修改pom文件,添加坐标
-
org.springframework.cloud spring-cloud-starter-gatewaycom.alibaba.cloud spring-cloud-starter-alibaba-nacos-discovery -
配置 yml文件:application.yml(yml文件中的格式要严格遵守下列代码格式)
-
spring.cloud.gateway.discovery.locator.enabled为true,表明gateway开启服务注册和发现的功能,并且spring cloud gateway自动根据服务发现为每一个服务创建了一个router,这个router将以服务名开头的请求路径转发到对应的服务
#端口号 server: port: 10010 spring: application: name: test-gateway cloud: nacos: discovery: server-addr: 127.0.0.1:8848 #nacos服务地址 gateway: discovery: locator: enabled: true #开启服务注册和发现的功能,自动创建router以服务名开头的请求路径转发到对应的服务 -
编写启动类
package com.czxy; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @SpringBootApplication @EnableDiscoveryClient public class TestGatewayApplication { public static void main(String[] args) { SpringApplication.run(TestGatewayApplication.class, args); } }测试
-



