前阵子看了一个大佬的一篇文章,始终不得其法。网关即网络关卡
文中提到,网关类似设计模式中的外观模式,后来看了外观模式,似乎稍微有所明白。确实很像,如下图
1,添加依赖
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
2、配置文档
zuul:
routes:
api-a-url:
path: /hello/**
url: http://localhost:9000/
#url: hello-service 注册到eureka上的服务名
请求符合/hello/ **规则的访问都将被路由转发到http://localhost:9000/地址上,其中API-A-URL是路由的名字,可以任意定义。