There is no @EnableGateway annotation in Spring Cloud Gateway. You get a gateway by adding the Spring Cloud Gateway starter to a Spring Boot application and defining routes, either in configuration or in Java. Auto-configuration does the rest, so a plain @SpringBootApplication class is enough.
If you have seen @EnableGateway in a tutorial, it was either invented or confused with annotations such as @EnableDiscoveryClient and @EnableZuulProxy from older Spring Cloud setups.
@EnableGateway@EnableGatewaySpring Cloud Gateway is built on Spring WebFlux and Project Reactor, and it is switched on by Spring Boot auto-configuration. The presence of the gateway starter on the classpath is the signal. The old Netflix Zuul 1 gateway used @EnableZuulProxy; Zuul 1 was removed from Spring Cloud, and Spring Cloud Gateway is its replacement. Gateway needs no equivalent annotation.
Two practical consequences follow:
spring.cloud.gateway.enabled=false.spring-boot-starter-web; mixing those two starters in one application is not supported.Import the Spring Cloud BOM that matches your Spring Boot version, then add the starter:
The starter brings in WebFlux, so you do not add spring-boot-starter-webflux yourself. In the newer release trains, the project was reorganised into a WebFlux server and a Spring MVC (servlet) server variant, with artifacts named spring-cloud-starter-gateway-server-webflux and spring-cloud-starter-gateway-server-webmvc, and configuration properties under spring.cloud.gateway.server.webflux.*. Check the reference documentation for the release train you use, because the old artifact name and property prefix are deprecated there. The examples below use the classic names that older and current Boot 3 setups know.
A route has an id, a destination uri, predicates that decide when it matches, and optional filters that change the request or response.
With both services running, a request to http://localhost:8080/orders/17 is forwarded to http://localhost:8081/orders/17 with the extra header attached.
The Java DSL is useful when routes depend on code or conditions:
The application class stays minimal:
When a discovery client is on the classpath (see @EnableDiscoveryClient), a route can target a service name with the lb:// scheme, and Spring Cloud LoadBalancer picks an instance:
You can also let the gateway create routes for every registered service automatically with spring.cloud.gateway.discovery.locator.enabled=true. That is convenient for development, but explicit routes are easier to secure and reason about in production.
| Type | Examples | Purpose |
|---|---|---|
| Predicate | Path, Host, Method, Header, Query, After | Decide whether a route matches |
| Filter | AddRequestHeader, StripPrefix, RewritePath, CircuitBreaker, RequestRateLimiter | Modify the exchange or protect the backend |
| Global filter | Custom GlobalFilter bean | Cross-cutting logic such as logging or authentication |
A global filter is just a bean:
None. Add the gateway starter and define routes. Spring Boot auto-configuration creates the gateway infrastructure.
The classic gateway is reactive and does not work with spring-boot-starter-web. Newer release trains offer a separate servlet-based gateway variant for MVC applications.
Spring Cloud Gateway replaced Netflix Zuul 1 as the supported API gateway in Spring Cloud.
Set spring.cloud.gateway.enabled=false, or remove the starter from the build.
Spring Cloud Gateway has no @EnableGateway annotation. Add the starter, keep @SpringBootApplication, and describe behaviour with routes, predicates and filters in YAML or Java. Use lb:// URIs with a discovery client, and check the artifact and property names for your Spring Cloud release train.