- Java 21
- Spring Boot 4 RC1
- Example Project: https://github.com/hantsy/spring7-sandbox/tree/master/boot-api-versioning-webmvc
When I wrote the example codes, I found there is no convenient methods for configuring API versioning.
The MockMvcBuilderCustomizer lack a defaultApiVersion existed in other Customizers.
BTW, it seems MockRestServiceServer is also not updated for apiversion mock/assertion.
Comment From: rstoyanchev
There is such support, so it's unclear what you mean or what you've tried. The referenced project has a test with an autowired MockMvc. That's configurable through a MockMvcBuilderCustomizer. On ConfigurableMockMvc builder you can set the version inserter for the request side. For the handling side, the standalone builder accepts an ApiVersioningStrategy, or if using an ApplicationContext based setup, then it's picked up from your application config.
Comment From: hantsy
The MockMvcBuilderCustomizer lack a defaultApiVersion existed in other Customizers.
Comment From: rstoyanchev
Good point, but there is defaultRequest that at least allows it:
standaloneSetup(new MusicController())
.defaultRequest(get("/").apiVersion("1.2")
.build()
Comment From: hantsy
For Spring Boot, when testing controller with @WebMvcTest and MockMvc, we do not need to use standaloneSetup. The apiVersion in the defaultRequest here does not resolve my question.