1. 程式人生 > >spring cloud: zuul: 微網關-簡單使用與路由配置

spring cloud: zuul: 微網關-簡單使用與路由配置

true art ble localhost server cli 圖片 tid zuul

spring cloud: zuul: 微網關-簡單使用與路由配置

首先引入依賴

<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-zuul</artifactId>
</dependency>
		
<dependency>
		<groupId>org.springframework.cloud</groupId>
		<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>

  

入口文件加入@EnableZuulProxy註解

@EnableZuulProxy
@SpringBootApplication
public class ZuulApplication {	

	public static void main(String[] args) {
		SpringApplication.run(ZuulApplication.class, args);
	}
}

  

application.properties

server.port = 8040
#spring
spring.application.name=spring-boot-zuul
#localhost
#user.userServicePath=http://localhost:7900/simple/
#eureka
eureka.client.healthcheck.enable=true
eureka.client.serviceurl.defaultzone=http://localhost:8761/eureka
eureka.instance.preferIpAddress=true #ip

  

啟動zuul服務,eureka服務,user服務

技術分享圖片

訪問:

http://192.168.1.4:8040/spring-boot-movie-ribbon/movie/1

http://192.168.1.4:8040/spring-boot-user/simple/3

技術分享圖片

技術分享圖片

二。配置zuul路由

application.properties

zuul.routes.spring-boot-user=/user/**

  

啟動,訪問

技術分享圖片

spring cloud: zuul: 微網關-簡單使用與路由配置