Spring Cloud Gateway 是一个基于 Spring Boot 的非阻塞 API 网关服务,它提供了动态路由、请求断言、过滤器等功能。
以下是关于 Spring Cloud Gateway 的示例:
package com.cherry.provider1.controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; @RestController @RequestMapping("product") public class ProductController { @RequestMapping("list") public String list(){ return "这是product列表"; } }
server.port=8009 spring.application.name=my_provider1 #注册中心的地址 eureka.client.service-url.defaultZone=http://localhost:8001/eureka/
package com.cherry.provider1; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; @SpringBootApplication @EnableEurekaClient public class Provider1Application { public static void main(String[] args) { SpringApplication.run(Provider1Application.class, args); } }
server.port=9001 spring.application.name=gateway spring.cloud.gateway.routes[0].id= gateway-service spring.cloud.gateway.routes[0].uri= http://localhost:8002 spring.cloud.gateway.routes[0].predicates[0]= Path=/building/welcome