Skip to content

Simplify API Versioning Config in WebTestClient #35246

@hantsy

Description

@hantsy

Java 21/Spring 7.0.0-M7/Spring Boot 4.0.0-M1, I attempted to write test code for the API with versioning. When building WebTestClient and setting up apiVersioning is not enough, an exception indicates that it requires ApiVersionInserter. I need to use both configurations together to get it to work.

this.webTestClient = WebTestClient
        .bindToController(new GreetingController())
        .apiVersioning(apiVersionConfigurer ->
                apiVersionConfigurer.useRequestHeader("X-API-Version").setDefaultVersion("1.0"))
        .configureClient()
        .apiVersionInserter(ApiVersionInserter.builder()
                .useHeader("X-API-Version")
                .build())
        .build();

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: webIssues in web modules (web, webmvc, webflux, websocket)status: waiting-for-triageAn issue we've not yet triaged or decided on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions