Affects: Spring WebFlux 5.2.9

From the documentation about Spring WebFlux controller annotated method arguments:

UriComponentsBuilder | For preparing a URL relative to the current request’s host, port, scheme, and path.

When reading this, I understood that the injected builder would include the full path to my controller method, which seemed confirmed by #20546 stating that an injected builder should behave like UriComponentsBuilder.fromHttpRequest(request).

However, when building a war that is deployed to tomcat 9.0.27 under the application context "/context":

@Controller
@RequestMapping ("/controller")
public class MyController {

  private static final Logger logger = LoggerFactory.getLogger (MyController.class);

  @GetMapping ("/method")
  public void method (
      UriComponentsBuilder builder,
      ServerHttpRequest request
  ) {
   logger.info ("Injected: {}", builder.build (emptyMap ())); // -> http://localhost:8080/
   logger.info ("Constructed: {}", UriComponentsBuilder.fromHttpRequest (request).build (emptyMap ())); // -> http://localhost:8080/context/controller/method
  }
}

Note that I’m fine if the spec changed after #20546 was drafted. The documentation however should be updated.

Interestingly, answers to #21449 state that the injected builder should be "application relative". My understanding of this sentence is that it should include the application context path, but not the controller path. This would have been exactly what I need, but isn’t what I see.

I haven’t tested what happens with non-reactive controllers. Obviously, we want the behavior to match in all three places: - WebFlux - Web MVC - latest documentation.

Comment From: rstoyanchev

Thanks for pointing this out. The intent with #21353 was to align with Spring MVC which uses ServletUriComponentsBuilder#fromServletMapping and the docs there do say:

For preparing a URL relative to the current request’s host, port, scheme, context path, and the literal part of the servlet mapping

So to align all 3 I'll make sure the path in WebFlux is application relative.