-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve documentation for uri(URI) method in WebTestClient regarding base URI #28058
Comments
I've edited your comment to improve the formatting. You might want to check out this Mastering Markdown guide for future reference. Specifically, please avoid the use of @-mentions for annotations. Instead, please ensure that annotations are formatted as literals or code snippets. |
As stated in the Javadoc for
By passing As stated in the Javadoc for
The Thus, the behavior you are experiencing is expected and by design; however, I think the Javadoc for |
This example works by adding the
|
If you feel that something can be documented better in Javadoc or in the reference docs for the core Spring Framework, please let us know in this issue tracker. Regarding the behavior of Thanks |
Affects: Spring Boot 2.6.3 and below
During one of my integration tests, to test one endpoint I encountered the following error:
I'm using the webflux starter version 2.6.3, but the problem I'm describing is reproducible with lower version.
These are the annotations applied to my test:
and this is the code is raising the issue:
After analyzing the problem, I found out that the issue is caused by the use of
@SpringBootTest(webEnvironment = RANDOM_PORT)
without@AutoConfigureWebTestClient
(this should be possible since@SpringBootTest
registers aWebTestClient
) and the use of theS uri(URI uri);
implementation in theUriSpec
interface inside theWebTestClient
interface.In other words by rewriting the test as:
The
DefaultWebTestClient
is injected with auriBuilderFactory
(DefaultUriBuilderFactory
) where its fieldprivate final UriComponentsBuilder baseUri;
is not null.In the first case the URI returned is missing the base URI (
http//host:port/
-- for example,/myUrl?year=2005
), whilst in the second case the URI returned contains the base URI (http//host:port/myUrl?year=2005
).Another workaround is to put (a redundant) annotation:
In this case the
DefaultWebTestClient
is injected withprivate final UriComponentsBuilder baseUri;
equals to null, then the methods:are consistent: both return the URI without the base URI, but in this case everything works.
The text was updated successfully, but these errors were encountered: