This version is still in development and is not considered stable yet. For the latest stable version, please use Spring Framework 7.0.6!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("API-Version");
	}
}
@Configuration
class WebConfiguration : WebMvcConfigurer {

	override fun configureApiVersioning(configurer: ApiVersionConfigurer) {
		configurer.useRequestHeader("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

To resolve from a path segment, you need to specify the index of the path segment expected to contain the version. The path segment must be declared as a URI variable, e.g. "/{version}", "/api/{version}", etc. where the actual name is not important. As the version is typically at the start of the path, consider configuring it externally as a common path prefix for all handlers through the Path Matching options.spring-doc.cn

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