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: 微网关-简单使用与路由配置
原文:https://www.cnblogs.com/achengmu/p/9932444.html