Spring
Follow
API Versioning in Spring
Spring Framework 7 introduces built-in API versioning support, addressing a common need that previously required manual implementation. The feature provides essential building blocks, focusing on server and client-side handling. Server-side, the `ApiVersionStrategy` manages application versioning preferences, parsing and validating requests. Configuration occurs via MVC or WebFlux configurations, using properties for Spring Boot applications. Controllers utilize the `version` attribute in `@RequestMapping` and related annotations, while functional endpoints employ the `version` request predicate. Client-side, the `ApiVersionInserter` adds the API version to requests, allowing easy version specification. Testing capabilities are enhanced with support in `RestTestClient`, `WebTestClient`, and `MockMvc`. Deprecation hints can be configured through a deprecation handler. The framework includes support for semantic versioning and baseline versions, enhancing flexibility. For further details, the official documentation and a sample project are available for experimentation.