Zuul路由前缀1

一 简介
zuul:
  prefix: /simple
  strip-prefix: false
  routes:
    microservice-provider-user: /user/**
这样访问Zuul的simple/microservice-provider-user/1路径,请求将转发到microservice-provider-user的/simple/1
二 示例
1 用户微服务控制器配置
  @GetMapping(value={"/simple/{id}"})
  public User findById(@PathVariable Long id) {
    User findOne = this.userRepository.findOne(id);
    return findOne;
  }
2 Zuul的配置
server:
  port: 8040
spring:
  application:
    name: microservice-gateway-zuul
eureka:
  client:
    service-url:
      defaultZone: http://localhost:8761/eureka/
  instance:
    prefer-ip-address: true
zuul:
  prefix: /simple
  strip-prefix: false
  routes:
    microservice-provider-user: /user/**
logging:
  level:
com.netflix: DEBUG
   
# 访问Zuul的/simple/microservice-provider-user/1路径,请求将会被转发到microservice-provider-user的/simple/1,,可以查看日志打印,有助于理解。 
2 测试
输入 http://localhost:8040/simple/user/1
或者输入 http://localhost:8040/simple/microservice-provider-user/1
浏览器输出:
Zuul路由前缀1_第1张图片

你可能感兴趣的:(微服务)