Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Cloud Gateway Simple example not working

Most basic Spring Cloud Gateway app not working.

application.yml

server:
    port: 9000

GatewayApplication.java

@SpringBootApplication
public class GatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
    }

    @Bean
    public RouteLocator routeLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("test", r -> r.path("/test")
                        .uri("http://httpbin.org:80"))
                .build();
    }
}

Postman: http://localhost:9000/test

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>404 Not Found</title>
<h1>Not Found</h1>
<p>The requested URL was not found on the server.  If you entered the URL         
manually please check your spelling and try again.</p>

Postman: http://localhost:9000/test2

{
   "timestamp": "2019-06-26T22:24:34.208+0000",
   "path": "/test2",
   "status": 404,
   "error": "Not Found",
   "message": null
}
like image 335
Sam Avatar asked Dec 23 '25 00:12

Sam


1 Answers

http://localhost:9000/test

Your first request will be send to http://httpbin.org:80/test. And Because there is no request mapping for /test in http://httpbin.org, You got 404 Not Found response from http://httpbin.org.


http://localhost:9000/test2

Your second request will not be sent anywhere. "/test2" cannot be sent, because your route config is "/test". So you got 404 Not Found response from your gateway application. If you want to apply same routing rule to "/test2", your config have to be "/test**"

like image 145
dlsrb6342 Avatar answered Dec 28 '25 23:12

dlsrb6342



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!