Spring Cloud 2-Zuul 网关服务(六)

 

 

1.pom.xml

<!-- zuul 网关服务 -->
<dependency>
   <groupId>org.springframework.cloud</groupId>
   <artifactId>spring-cloud-starter-netflix-zuul</artifactId>
</dependency>

2.application.yml

spring:
  application:
    name: zuul-proxy

zuul:
  routes: 
    a: 
      path: /a/**
      url: http://localhost:8091/
    b:
      path: /b/**
      serviceId: hystrix-client
      
server:
  port: 8888
  • 把请求路径a代理到http://localhost:8091/ 通过url指定
  • 把请求路径b代理到hystrix-client 通过serviceId指定

Application.java

@EnableZuulProxy
@SpringBootApplication
public class ZuulProxyApplication {

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

}

访问: http://localhost:8888/a/hystrix/he
Hello World!
访问: http://localhost:8888/b/hystrix/he
Hello World!

posted @ 2019-01-01 14:22  林宇风  阅读(334)  评论(0编辑  收藏  举报