This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Framework 6.2.10!spring-doc.cn

API Version

To enable API versioning, use the ApiVersionConfigurer callback of WebMvcConfigurer:spring-doc.cn

@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")
	}
}

You can resolve the version through one of the built-in options listed below, or alternatively use a custom ApiVersionResolver:spring-doc.cn

When using a path segment, consider configuring a shared path prefix externally in Path Matching options.

By default, the version is parsed with SemanticVersionParser, but you can also configure a custom ApiVersionParser.spring-doc.cn

Supported versions are transparently detected from versions declared in request mappings for convenience, but you can turn that off through a flag in the MVC config, and consider only the versions configured explicitly in the config as supported. Requests with a version that is not supported are rejected with InvalidApiVersionException resulting in a 400 response.spring-doc.cn

You can set an ApiVersionDeprecationHandler to send information about deprecated versions to clients. The built-in standard handler can set "Deprecation", "Sunset", and "Link" headers based on RFC 9745 and RFC 8594.spring-doc.cn

Once API versioning is configured, you can begin to map requests to controller methods according to the request version.spring-doc.cn