如何在Spring Webflux中重定向请求? [英] How to redirect a request in spring webflux?

查看:1717
本文介绍了如何在Spring Webflux中重定向请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Spring WebFlux中创建重定向Rest Web服务?看来WebFlux中还没有重定向功能!

how can I create a redirect rest web service in spring WebFlux? It seems that there is no redirect functionality in WebFlux yet!

我想要这样的东西:

 @Bean
RouterFunction<ServerResponse> monoRouterFunction() {
    return 
        route(GET("/redirect/{id}"),{
            req -> req.Redirect( fetchAUrlFromDataBase() )
        })

推荐答案

@Bean
RouterFunction<ServerResponse> routerFunction() {
     route(GET("/redirect"), { req ->
          ServerResponse.temporaryRedirect(URI.create(TargetUrl))
                    .build()
        }
    })

}

非常感谢Johan Magnusson

Thanks you very much Johan Magnusson

这篇关于如何在Spring Webflux中重定向请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆