Zuul 搭建

Step 3-1:新建service-zuul

Zuul 搭建_第1张图片

 

注:不熟悉如何搭建Spring Boot 项目,请点击

 

Step 3-2:在其入口applicaton类加上注解@EnableZuulProxy,开启zuul的功能:

@SpringBootApplication
@EnableZuulProxy
@EnableDiscoveryClient
public class ServiceZuulApplication {

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

}

 Step 3-3:加上配置文件application.yml加上以下的配置代码:

eureka:
  client:
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/
server:
  port: 8769
spring:
  application:
    name: service-zuul
zuul:
  routes:
    api-a:
      path: /api-a/**
      serviceId: service-ribbon
    api-b:
      path: /api-b/**
      serviceId: service-feign
    abc:
      path: /qwer/**
      serviceId: service-ribbon
    123:
      path: /123/**
      serviceId: service-feign
  •   启动后效果:访问 http://localhost:8764/api-a/hi?name=forezp                           

浏览器显示:

hi forezp,i am from port:8762

  •  访问 http://localhost:8764/123/hi?name=forezp 

浏览器显示:

hi forezp,i am from port:8762

 

你可能感兴趣的:(读书笔记)