一, 什么是网关
Zuul 的主要功能是路由转发和过滤器. 路由功能是微服务的一部分, 比如 / API/user 转发到到 user 服务,/API/shop 转发到到 shop 服务. zuul 默认和 Ribbon 结合实现了负载均衡的功能, 类似于 nginx 转发.
二, 搭建 SpringCloud 网关
创建工程 service-zuul 目录展示
1. 导入依赖
- <!--eureka 依赖 -->
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
- </dependency>
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
- </dependency>
- <dependencyManagement>
- <dependencies>
- <!--springCloud 依赖 -->
- <dependency>
- <groupId>org.springframework.cloud</groupId>
- <artifactId>spring-cloud-dependencies</artifactId>
- <version>Greenwich.RELEASE</version>
- <type>pom</type>
- <scope>import</scope>
- </dependency>
- </dependencies>
- </dependencyManagement>
- View Code
2.application.YAML 配置文件
3.ZuulApp 启动类
来源: http://www.bubuko.com/infodetail-3340791.html