在 基于 " sringcloud(十四)、ribbon負載均衡政策應用案例 "所有工程的基礎上,進行如下操作進行網關設定
1、建立eureka-client-consumer-zuul 工程
2、在建立的時候引入如下依賴
3.編寫項目的pom.xml
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
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.啟動類的設定
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上的請求
7.通過統一網關通路調用者consumer-empdept-p-one上的請求
轉載于:https://www.cnblogs.com/holly8/p/11435687.html