Skip to content

Using a URI variable for port in WebClient causes an IllegalStateException #32003

Closed
@lkleeven

Description

@lkleeven

Affects: 6.1.2

In Spring Framework 6.1.1, the following little code snippet worked without any problems:

var uriSpec = WebClient.create()
            .get()
            .uri("http://localhost:{port}/first", 8080);

Now this same code causes the following IllegalStateException:

java.lang.IllegalStateException: The port contains a URI variable but has not been expanded yet: {port}

	at org.springframework.web.util.HierarchicalUriComponents.getPort(HierarchicalUriComponents.java:193)
	at org.springframework.web.util.HierarchicalUriComponents.toUriString(HierarchicalUriComponents.java:488)
	at org.springframework.web.util.DefaultUriBuilderFactory$DefaultUriBuilder.toUriString(DefaultUriBuilderFactory.java:416)
	at org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.uri(DefaultWebClient.java:230)
	at org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.uri(DefaultWebClient.java:199)

This seems related to the changes made in #30027 and the already mentioned #31882.

Is this a bug, or are we no longer allowed to use URI variables inside the base URL?

Metadata

Metadata

Assignees

Labels

in: webIssues in web modules (web, webmvc, webflux, websocket)type: regressionA bug that is also a regression

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions