创建网关项目(Spring Cloud Gateway)

匿名 (未验证) 提交于 2019-12-03 00:13:02


        <properties>         <java.version>1.8</java.version>         <spring-cloud.version>Greenwich.SR3</spring-cloud.version>     </properties>      <dependencies>         <dependency>             <groupId>org.springframework.cloud</groupId>             <artifactId>spring-cloud-starter-gateway</artifactId>         </dependency>          <dependency>             <groupId>org.springframework.boot</groupId>             <artifactId>spring-boot-starter-test</artifactId>             <scope>test</scope>         </dependency>     </dependencies>      <dependencyManagement>         <dependencies>             <dependency>                 <groupId>org.springframework.cloud</groupId>                 <artifactId>spring-cloud-dependencies</artifactId>                 <version>${spring-cloud.version}</version>                 <type>pom</type>                 <scope>import</scope>             </dependency>         </dependencies>     </dependencyManagement>

将项目目录下的/src/main/resources/application.properties文件重命名为application.yml,properties配置格式和yml配置格式是等效的,而yml配置格式能更好的被配置中心使用,所以我们使用yml配置格式。

application.yml配置文件内容修改如下:

server:  port: 9000 spring:   cloud:    gateway:       routes:         - id: first_route           uri: https://github.com/sunweisheng           predicates:             - Path=/test
  • port:网关服务端口
  • routes:路由集合
  • id:路由的唯一标示
  • uri:路由目标地址
  • predicates:路由条件,如果为true则路由到uri

predicates(还有filters)的种类很多请参考Spring Cloud Gateway官网

访问127.0.0.1:9000/test

Github仓库:https://github.com/sunweisheng/spring-cloud-example

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!