Hello spring development team. I've ran across this problem during work and believe that it might be a bug.

Given the following controller:

@RestController
public class TestController {
    @GetMapping("${test.get}")
    public Mono<Map<String, String>> get() {
        return Mono.just(Map.of("Hello", "world"));
    }
}

with the following application.yaml

test:
  get: /test

and the following test:

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.MOCK)
class TestControllerTest {

    @Test
    void get() {
        WebTestClient webTestClient = WebTestClient.bindToController(new TestController()).build();

        webTestClient.get()
                .uri("/test")
                .exchange()
                .expectStatus().is2xxSuccessful();
    }
}

When running the above test the following exception occurs:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webHandler' defined in org.springframework.web.reactive.config.DelegatingWebFluxConfiguration: Initialization of bean failed; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping' defined in org.springframework.web.reactive.config.DelegatingWebFluxConfiguration: Invocation of init method failed; nested exception is org.springframework.web.util.pattern.PatternParseException: Char '.' is not allowed in a captured variable name

However when running the test with RANDOM_PORT webEnvironment as per the following test:

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class TestControllerTest {
    @LocalServerPort
    private int port;

    @Test
    void get() {
        WebTestClient webTestClient = WebTestClient.bindToServer().baseUrl("http://localhost:" + port).build();

        webTestClient.get()
                .uri("/test")
                .exchange()
                .expectStatus().is2xxSuccessful();
    }
}

The test passed without much fanfare. The mock web environment also pass if I replace the placeholder with the actual url.

I tested this on spring version 2.5.4

Comment From: rstoyanchev

In this scenario where you're binding directly to the controller, there is most likely no value for "test.get", if it comes from application.properties for example, and the placeholder remains not substituted.

You could use @AutoConfigureWebTestClient or alternatively set the property in the environment. We could consider exposing something on WebTestClient.ControllerSpec to declare properties manually.

Comment From: spring-projects-issues

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

Comment From: EnviableYapper0

I see, thank you for the information. I think a method for manually setting properties would be nice for those who like to set everything in test code.