1.Spring Cloud Gateway简介

  Spring Cloud Gateway是Spring Cloud官方推出的第二代网关框架,取代Zuul网关。网关作为流量的,在微服务系统中有着非常作用,网关常见的功能有路由转发、权限校验、限流控制等作用。

  2.创建工程

  本文我们采用最新的Spring Cloud 版本“Finchley.SR2”,注意该版本对应Spring Boot为2x。官方推荐的是:2.0.6.RELEASE版本。

  父项目导入如下包:

  org.springframework.boot

  spring-boot-starter-parent

  2.0.8.RELEASE

  pom

  import

  org.springframework.cloud

  spring-cloud-dependencies

  Finchley.SR2

  pom

  import

  org.mybatis.spring.boot

  mybatis-spring-boot-starter

  1.3.0

  com.alibaba

  dubbo

  2.6.6

  com.alibaba.spring

  spring-context-support

  1.0.2

  org.apache.curator

  curator-framework

  4.0.1

  org.apache.zookeeper

  zookeeper

  3.4.6

  org.hibernate

  hibernate-validator

  6.0.9.Final

  gateway网关服务导入如下jar:

  org.springframework.cloud

  spring-cloud-starter-gateway

  org.springframework.boot

  spring-boot-starter-test

  test

  org.springframework.boot

  spring-boot-starter-aop

  com.alibaba

  dubbo

  com.alibaba.spring

  spring-context-support

  org.apache.curator

  curator-framework

  org.apache.zookeeper

  zookeeper

  org.slf4j

  slf4j-log4j12

  log4j

  log4j

  com.uaf.credit

  uaf-credit-api

  org.springframework.boot

  spring-boot-starter-web

  父项目统一管理jar包的版本,子项目就不必再添加jar对应的版本号

  网关服务的yml配置如下:

  server:

  port: 8817

<