spring cloud: zuul: 微閘道器-簡單使用與路由配置
阿新 • • 發佈:2018-11-08
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/**
啟動,訪問