在 基于 " sringcloud(十四)、ribbon负载均衡策略应用案例 "所有工程的基础上,进行如下操作进行网关设置

1、创建eureka-client-consumer-zuul 工程

2、在创建的时候引入如下依赖

springcloud(十六)、feign+hystrix+ribbon+zuul应用案例_ide

 

 

 

3.编写项目的pom.xml

springcloud(十六)、feign+hystrix+ribbon+zuul应用案例_ide_02springcloud(十六)、feign+hystrix+ribbon+zuul应用案例_SpringCloud_03
 1     <dependencies>
 2         <dependency>
 3             <groupId>org.springframework.boot</groupId>
 4             <artifactId>spring-boot-starter-web</artifactId>
 5         </dependency>
 6         <dependency>
 7             <groupId>org.springframework.cloud</groupId>
 8             <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
 9         </dependency>
10         <dependency>
11             <groupId>org.springframework.cloud</groupId>
12             <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
13         </dependency>
14 
15         <dependency>
16             <groupId>org.springframework.boot</groupId>
17             <artifactId>spring-boot-starter-test</artifactId>
18             <scope>test</scope>
19         </dependency>
20     </dependencies>
pom.xml

 

4.编写application.properties

springcloud(十六)、feign+hystrix+ribbon+zuul应用案例_ide_02springcloud(十六)、feign+hystrix+ribbon+zuul应用案例_SpringCloud_03
 1 spring.application.name=eureka-zuul
 2 
 3 server.port=8766
 4 
 5 eureka.client.serviceUrl.defaultZone=http://localhost:8761/eureka/
 6 
 7 #路由配置:配置访问映射路径,所有的其他项目引用采用统一的端口,统一的ip地址,
 8 #以不同的前缀区分不同项目中的请求
 9 #配置规则:zuul.routes.其他引用的名字=/前缀/**
10 zuul.routes.consumer-empdept-p-one=/con/**
11 zuul.routes.provider-empdept=/pro/**
application.properties

 

5.启动类的设置

springcloud(十六)、feign+hystrix+ribbon+zuul应用案例_ide_02springcloud(十六)、feign+hystrix+ribbon+zuul应用案例_SpringCloud_03
 1 package cn.kgc;
 2 
 3 import org.springframework.boot.SpringApplication;
 4 import org.springframework.boot.autoconfigure.SpringBootApplication;
 5 import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
 6 import org.springframework.cloud.netflix.zuul.EnableZuulProxy;
 7 
 8 @EnableZuulProxy
 9 @EnableEurekaClient
10 @SpringBootApplication
11 public class EurekaClientConsumerZuulApplication {
12 
13     public static void main(String[] args) {
14         SpringApplication.run(EurekaClientConsumerZuulApplication.class, args);
15     }
16 
17 }
启动类

 

6.通过统一网关访问提供者provider-empdept上的请求

springcloud(十六)、feign+hystrix+ribbon+zuul应用案例_ide_08

 

 

7.通过统一网关访问调用者consumer-empdept-p-one上的请求

springcloud(十六)、feign+hystrix+ribbon+zuul应用案例_.net_09