其他分享
首页 > 其他分享> > 如何在Spring Webflux中重定向请求?

如何在Spring Webflux中重定向请求?

作者:互联网

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

我想要这样的东西:

 @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

标签:spring-webflux,url-redirection,spring-boot,spring
来源: https://codeday.me/bug/20191109/2010816.html