3Zuul 指定路由 · SpringCloud微服务实战 · 看云

3. 指定路由

导航

本节代码地址


3.1 新建项目

8537d5e366eee90bbee1c5e8a6687665_MD5.webp

3.2 新建启动类

记得开启@EnableZuulProxy注解

@EnableZuulProxy
@EnableDiscoveryClient
@SpringBootApplication
public class FwZuulApplication {
    public static void main(String[] args) {
        SpringApplication.run(FwZuulApplication.class, args);
    }


}

3.3 应用配置

server:
  port: 8679
spring:
  application:
    name: fw-gateways-zuul
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
zuul:
  routes:
    fw-cloud-ribbon-server: 
      path: /ribbon

当然还可以简写

zuul:
  routes:
    fw-cloud-ribbon-server: 
      path: /ribbon

也可以写成,path 可以省略

zuul:
  routes:
    fw-cloud-ribbon-server:  /ribbon

3.4 启动项目

浏览器或Postman 输入localhost:8678/ribbon/user/1
dcb7ffd65463f534d3e10261cf1b4bf5_MD5.png