【问题标题】:Api-Gateway Spring boot Variable URIApi-Gateway Spring boot 变量 URI
【发布时间】:2018-12-05 04:42:12
【问题描述】:

我上个月在实习中开始学习弹簧靴,所以我遇到了一些问题。我正在研究spring boot的api网关。我想配置一个可编程的 URI。我给你举个例子:

@Bean
public RouteLocator myRoutes (RouteLocatorBuilder builder){
return builder.routes()
            .route(r -> r.path("/test/{appID}")

                    .uri("http://aa.aa.com/aaaa/app/{appID}")

            )

我想使用 {appID} 访问每个 URI。

你能帮帮我吗?

谢谢。

【问题讨论】:

    标签: spring spring-boot api-gateway


    【解决方案1】:

    路由定位器请参考以下代码

    @Bean
        public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
            return builder.routes()
              .route("r1", r -> r.host("**.yourdomainname.com")
                .and()
                .path("/abc")
                .uri("http://yourdomainname.com"))
              .route(r -> r.host("**.yourdomainname.com")
                .and()
                .path("/myOtherRouting")
                .filters(f -> f.prefixPath("/myPrefix"))
                .uri("http://othersite.com")
                .id("myOtherID"))
            .build();
        }
    

    希望它能解决您的问题。 如果您有更多疑问,请参考here

    【讨论】:

    • 我想从localhost:8080/projects重定向到http://*.*.com:8080/mos-resources-rs/1.0/projects,我写了这段代码,不幸的是它不起作用...那是我的代码 .route("Get/Put/Post project", r -> r.host("api.***.com") .and() .path("/projects") .filters (f -> f.setPath("/mos-resources-rs/1.0/projects")) .uri(OutputHost)) .build();
    猜你喜欢
    • 2018-06-19
    • 1970-01-01
    • 2021-05-13
    • 2021-11-03
    • 2021-04-04
    • 1970-01-01
    • 2020-04-05
    • 2020-11-26
    • 2022-07-21
    相关资源
    最近更新 更多