Spring Cloud Gateway

2020-05-08  本文已影响0人  慵懒的阳光丶

一、快速入门

1.引入依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <artifactId>spring-cloud-gateway</artifactId>
    <groupId>com.alibaba.test</groupId>
    <version>1.0.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>
    </dependencies>


    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR3</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
</project>

2.配置application.yml

#说明:这种方式的配置是将访问路径中包含?to=baidu的请求路由到百度的网址
spring:
  cloud: 
    gateway:
      routes:
      - id: query_route
        uri: https://www.baidu.com
        predicates:
        - Query=to,baidu
server:
  port: 8082
image.png
上一篇 下一篇

猜你喜欢

热点阅读