yml中的Spring云ZUUL配置?

时间:2018-03-02 14:14:27

标签: spring spring-boot yaml spring-cloud netflix-zuul

我想在 application.yml 文件中配置 ZUUL 属性,但不知怎的,我无法在 yml 文件中定义路由(我在浏览器中找不到页面)。它虽然在 application.properties 文件中完美运行。以下是application.propertiesapplication.yml文件中的属性。

application.properties

#subway is the application context name of a microservice. This works perfectly fine.
zuul.routes.**subway**.url=http://localhost:7777/

applcation.yml档案

zuul:
  routes:
    subway:
      path: /subway/**
      url: http://localhost:7777/

也试过:

zuul:
  routes:
      service-id: /subway/**
      path: /subway/**
      url: "http://localhost:7777/"
      strip-prefix: false
      service-id: /subway1/**
      path: /subway1/**
      strip-prefix: false
      url: "http://localhost:6666/"
      service-id: /subway2/**
      path: /subway2/**
      url: "http://localhost:5555/"
      strip-prefix: false

我得到例外

  

引起:org.yaml.snakeyaml.parser.ParserException:解析时   在阅读器'第12行第7列中的MappingNode:             service-id:/ subway / **

我有什么遗漏的吗?

1 个答案:

答案 0 :(得分:2)

以下是它的工作原理。谢谢@harshavmb和@pvpkiran:

zuul:
  routes:
    subway:
      service-id: /subway/**
      path: /subway/**
      url: "http://localhost:7777/"
      strip-prefix: false
    subway1:
      service-id: /subway1/**
      path: /subway1/**
      strip-prefix: false
      url: "http://localhost:6666/"
    subway2:
      service-id: /subway2/**
      path: /subway2/**
      url: "http://localhost:5555/"
      strip-prefix: false