Cloud Native 5 min read

Spring Cloud Gateway: Introduction, Architecture, Setup and Demo

This article provides a comprehensive guide to Spring Cloud Gateway, covering its role as an API gateway, core features, underlying principles, step‑by‑step module creation, Maven dependency configuration, application annotations, YAML routing examples, and a runnable demo for building cloud‑native microservice architectures.

Wukong Talks Architecture
Wukong Talks Architecture
Wukong Talks Architecture
Spring Cloud Gateway: Introduction, Architecture, Setup and Demo

1. Gateway Overview

Spring Cloud Gateway serves as the entry point for traffic in a microservice system, offering routing, authentication, and rate‑limiting capabilities. It replaces Netflix Zuul as the second‑generation gateway framework in the Spring Cloud ecosystem.

2. Gateway Principles

Requests first reach the API gateway, which discovers service instances via a registration center (e.g., Nacos) and routes them to the appropriate microservice.

Spring Cloud Gateway architecture diagram.

3. Creating the Gateway Module

Use the Spring Initializr to generate a new module, select the "Gateway" dependency, and add the module to the multi‑module project.

4. Adding the Dependency

<module>passjava-gateway</module>

5. Configuring the Gateway

Import the common module that already includes the Nacos client, then add the @EnableDiscoveryClient annotation to the main application class.

@RefreshScope
@EnableDiscoveryClient
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class PassjavaGatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(PassjavaGatewayApplication.class, args);
    }
}

6. Gateway Demo (application.yml)

spring:
  cloud:
    gateway:
      routes:
        - id: route_qq
          uri: http://www.qq.com
          predicates:
            - Query=url,qq
        - id: route_baidu
          uri: http://www.baidu.com
          predicates:
            - Query=url,baidu

The first rule forwards requests containing url=qq to QQ, and the second forwards url=baidu to Baidu.

7. Code Repository

All source code is available at https://github.com/Jackson0714/PassJava-Platform .

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaCloud NativeDockerMicroservicesgatewaySpring Cloud
Wukong Talks Architecture
Written by

Wukong Talks Architecture

Explaining distributed systems and architecture through stories. Author of the "JVM Performance Tuning in Practice" column, open-source author of "Spring Cloud in Practice PassJava", and independently developed a PMP practice quiz mini-program.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.