Issue
How do I convert the following Spring MVC code to spring webflux?
@GetMapping(path = "/connect")
@ResponseStatus(HttpStatus.FOUND)
public ModelAndView connect() {
String oauthUrl = "https://google.com";
RedirectView redirect = new RedirectView(oauthUrl);
redirect.setExpandUriTemplateVariables(false);
return new ModelAndView(redirect);
}
Solution
@RestController
public class TestController {
@GetMapping(path = "/redirect")
public Mono<ResponseEntity> redirect() {
return Mono.just(ResponseEntity
.status(HttpStatus.TEMPORARY_REDIRECT)
.header("Location", "https://google.com?param=ABCD")
.build());
}
}
or the .header(...)
can be replaced by .location(new URI(...))
Answered By - Guy Assaf
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.