Spring cloud api gateway giving 404 not found

6 days ago 8
ARTICLE AD BOX

I have a microservices namely COCT_HS_BUDGET-MICROSERVICES which is properly registered in a eureka server as well the Housing_GatewaY acting as a spring cloud gateway.

Eureka Server Dashboard

Accordingly, the Spring Cloud Gateaway has the following dependencies and configuration

<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>4.0.2</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>CoCT</groupId> <artifactId>Housing_Gateway</artifactId> <version>0.0.1-SNAPSHOT</version> <name>Housing_Gateway</name> <description>Housing_Gateway</description> <url/> <licenses> <license/> </licenses> <developers> <developer/> </developers> <scm> <connection/> <developerConnection/> <tag/> <url/> </scm> <properties> <java.version>17</java.version> <spring-cloud.version>2025.1.0</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway-server-webflux</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-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> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project>

Application.properties

spring.application.name=Housing_Gateway server.port=8085 spring.cloud.gateway.discovery.locator.enabled=true spring.cloud.gateway.routes[0].id=coct_hs_budget_microservices spring.cloud.gateway.routes[0].uri=lb://COCT_HS_BUDGET_MICROSERVICES spring.cloud.gateway.routes[0].predicates[0]=Path=/app1/** eureka.client.service-url.defaultZone=http://localhost:8761/eureka/

For testing purpose, I created a simple method in the microservices in order to test the above routes and predicate.

microservices:

package CoCT.CoCT_HS_Budget_Microservices; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.r2dbc.repository.config.EnableR2dbcRepositories; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @SpringBootApplication public class CoCtHsBudgetMicroservicesApplication { public static void main(String[] args) { SpringApplication.run(CoCtHsBudgetMicroservicesApplication.class, args); } @RestController class Service1Controller { @GetMapping("/app1/hello") public String hello() { return "Hello From Service "; } } }

Putting all together, I built the URL http://localhost:8085/COCT_HS_BUDGET_MICROSERVICES/app1/hello which, for my understanding, refers to the cloud gateway API port, the name of the service and the route and predicate. Yet a not found , status 404 is thrown out when the above URL is hit.

Thanking in advance.

Read Entire Article