春季引导云网关 – 除一个端点外,始终返回404。

huangapple 未分类评论51阅读模式
英文:

Spring boot cloud gateway - always 404 except one endpoint

问题

以下是您要翻译的内容:

我只想让Spring Boot Cloud Gateway运行起来。
使用以下代码,在/get端点上获得了结果。

其他任何情况都返回404。因此,/test或者我添加的任何其他端点都返回404。

@SpringBootApplication
@RestController
@EnableConfigurationProperties(UriConfiguration.class)
public class ApigatewayApplication {

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

    @Bean
    public RouteLocator routes(RouteLocatorBuilder builder, UriConfiguration uriConfiguration){
        return builder.routes()
                .route(p -> p
                        .path("/get")
                        .filters(f -> f.addRequestHeader("Hello", "World"))
                        .uri(uriConfiguration.getTestUrl()))
                .route(p -> p
                        .path("/test")
                        .filters(f -> f.addRequestHeader("Hello", "World"))
                        .uri(uriConfiguration.getTestUrl()))
                .build();
    }
}

我按照教程操作,但不知道为什么一个端点能正常工作,而其他端点却不能。
谢谢

英文:

I just want to get the Spring Boot Cloud Gateway running.
I get a result with the following Code with the /get endpoint.

anything else, returns 404. So /test or any other endpoint i add returns 404.

@SpringBootApplication
@RestController
@EnableConfigurationProperties(UriConfiguration.class)
public class ApigatewayApplication {

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

    @Bean
    public RouteLocator routes(RouteLocatorBuilder builder, UriConfiguration uriConfiguration){
        return builder.routes()
                .route(p -> p
                        .path("/get")
                        .filters(f -> f.addRequestHeader("Hello", "World"))
                        .uri(uriConfiguration.getTestUrl()))
                .route(p -> p
                        .path("/test")
                        .filters(f -> f.addRequestHeader("Hello", "World"))
                        .uri(uriConfiguration.getTestUrl()))
                .build();
    }
}

I followed the tutorial but i have no idea why one endpoint is working and the others not
thank you

答案1

得分: 0

好的,看起来如果多个路由具有相同的目标URI,则会出现404错误...

英文:

Ok, it looks like if multiple routes have the same destination URI, you get a 404...

huangapple
  • 本文由 发表于 2020年4月7日 04:21:52
  • 转载请务必保留本文链接:https://java.coder-hub.com/61068324.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定