First, what is the gateway
Zuul main function is to route forwarding and filters. Routing function is part of the micro-services, such as / api / user is forwarded to the service to the user, / api / shop to shop forwarded to the service. zuul default and Ribbon combination to achieve a load balancing feature, similar to the forward nginx.
Second, the build S pringCloud gateway
2.1 Create a project directory service-zuul show
2.2 import dependencies
<!--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>
2.3 application.yml profile
2.4 StartSpringCloudZuul startup class
package com.zn; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.EnableEurekaClient; import org.springframework.cloud.netflix.zuul.EnableZuulProxy; @EnableEurekaClient @SpringBootApplication @EnableZuulProxy public class StartSpringCloudZuul { public static void main(String[] args) { SpringApplication.run(StartSpringCloudZuul.class,args); } }
2.5 效果展示