Skip to content

SpringBootTest with RestClient.Builder that has base url + port already set. #40693

@xenoterracide

Description

@xenoterracide

I went scavenging the documentation couldn't find an annotation to configure RestClient.Builder although it does autowire it...

this is what I tried

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class AuthorizationServerTest {

  @Autowired
  RestClient.Builder restClientBuilder;

  @Test
  void noAuth() {
    var restClient = restClientBuilder
      .messageConverters(converters -> converters.addFirst(new OAuth2AccessTokenResponseHttpMessageConverter()))
      .build();

I expected it to be equivalent to

    var restClient = RestClient.builder()
      // .requestFactory(new HttpComponentsClientHttpRequestFactory()) not this because I'm doing this for tracing because of https://github.com/spring-projects/spring-framework/issues/32783 which might be better solved by Spring Boot
      .baseUrl("http://localhost:" + this.port)
      .messageConverters(converters -> converters)
org.springframework.web.client.ResourceAccessException: I/O error on GET request for "/authorize": Target host is not specified

Running with Spring Boot v3.2.5, Spring v6.1.6

Metadata

Metadata

Assignees

No one assigned

    Labels

    status: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions