This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Framework 6.2.6! |
API Version
To enable API versioning with a request header, use the following:
-
Java
-
Kotlin
@Configuration
public class WebConfiguration implements WebMvcConfigurer {
@Override
public void configureApiVersioning(ApiVersionConfigurer configurer) {
configurer.useRequestHeader("X-API-Version");
}
}
@Configuration
class WebConfiguration : WebMvcConfigurer {
override fun configureApiVersioning(configurer: ApiVersionConfigurer) {
configurer.useRequestHeader("X-API-Version")
}
}
Alternatively, the version can be resolved from a request parameter, from a path segment,
or through a custom ApiVersionResolver
.
When resolving from a path segment, consider configuring a path prefix once in Path Matching options. |
Raw version values are parsed with SemanticVersionParser
by default, but you can use
a custom ApiVersionParser.
"Supported" versions are transparently detected from versions declared in request mappings
for convenience, but you can also set the list of supported versions explicitly, and
ignore declared ones. Requests with a version that is not supported are rejected with an
InvalidApiVersionException
resulting in a 400 response.
Once API versioning is configured, you can begin to map requests to controller methods according to the request version.