Spring / Spring7 Intermediate to Advanced Interview questions
How is the API version resolved when a client sends no version header in Spring Framework 7?
The outcome depends on how the application configured its ApiVersionStrategy. If a default version is set via ApiVersionConfigurer.setDefaultVersion(...), an unversioned request is treated as if it had requested that default, and gets routed accordingly - this is the common choice for keeping older, pre-versioning clients working unchanged after versioning is introduced.
@Configuration public class WebConfig implements WebMvcConfigurer { @Override public void configureApiVersioning(ApiVersionConfigurer configurer) { configurer.useRequestHeader("API-Version").setDefaultVersion("1"); } }
If no default is configured and a mapping explicitly requires a version, Spring rejects the request with a client error rather than guessing which handler was intended. If an unversioned handler method also exists alongside versioned ones for the same path, that unversioned method typically acts as a catch-all for requests carrying no version at all. Spring's baseline-version syntax (version = "1.2+") adds further nuance: a handler declared this way matches any request version at or above 1.2, so as new minor versions are introduced, older baseline-declared handlers keep serving them without needing a new mapping for every increment.
More Related questions...