Java versioning strategy

In short, versioning means maintaining different endpoints of the same functionality in the service boundary layer and different consumers can consume different versions of the service based on the need. Now, it is important to understand why it is required? As a best practice, we should look for a strategy not to introduce versioning too so often to minimize the maintainability issues, rather we should design our services in such a way that they are backward compatible.

So, in short, we need versioning although this should be the last option of our services in certain scenarios. Today we will create a simple REST service that will return some Product details based on the product ID in the request, we need to implement different versions of this service, in the following sections we will see different approaches of this and also, we will see how things work with a real spring-boot project example.

There are mainly four types of approaches in REST API versioning as below, each method is the popular nut we need to take the call based on our actual scenario and standard.

You can leave your ad blocker on and still support us.

But we should not mix the approach in different services in the same domain, we should choose one approach and stick to that approach in all the services of that project. Here are the approaches at a high level, we will see those in action in the demonstration section. In this approach, we create different URLs for the service and consumers use the appropriate URL to consume the service.

This is the simplest approach and is extensively followed. As we can see we are changing the endpoint URL of the service method by introducing some version identifier. This is easier but has some side effects like. In this approach, we generally specify a custom header in the request and the server-side identify the actual controller method through this custom header. Create a free Team What is Teams? Learn more.


  1. jgitver: project versioning like a geek git.
  2. Subscribe to RSS!
  3. forex kort.

Ask Question. Asked 7 years, 4 months ago.

04 What is Semantic Versioning?

Active 1 year, 10 months ago. Viewed 86k times. The following is invalid in Spring RequestMapping VersionRange 1. For example Code: RequestMapping Edit Adding a bounty. Improve this question. Augusto Augusto That just says that you can use headers and, as I said, what spring provides out of the box is not sufficient to support APIs that are updated constantly.

Even worse the link on that answer uses the version in the URL. We need to support several versions of our APIs, these differences are usually minor changes that would make some calls from some clients incompatible it wont be strange if we need to support 4 minor versions, in which some endpoints are incompatible. I appreciate the suggestion to put it in the url, but we know that it's a step in the wrong direction, as we have a couple of apps with the version in the URL and there's a lot of work involved every time we need to bump the version.

Augusto, you actually you haven't too. Just design your API changes a way that doesn't break backward compatibility. Just give me example of changes that break compatibility and I show you how to make these changes in non-breaking fashion. Did you have a look at stackoverflow.


  1. get historical data forex.
  2. forexia silvadec.
  3. Versioning?

Show 7 more comments. Active Oldest Votes.

Versioning a REST API

Regardless whether versioning can be avoided by doing backwards compatible changes which might not always possible when you are bound by some corporate guidelines or your API clients are implemented in a buggy way and would break even if they should not the abstracted requirement is an interesting one: How can I do a custom request mapping that does arbitrary evaluations of header values from the request without doing the evaluation in the method body? To do so, you will have to: Create a new annotation VersionRange. Since you will have something like a best-match algorithm you will have to check whether methods annotated with other VersionRange values provide a better match for the current request.


  • Identifying the problems with versioning and exploring possible solutions..
  • incentive stock options income tax.
  • forex appreciation depreciation.
  • Implement a VersionRangeRequestMappingHandlerMapping based on the annotation and request condition as described in the post How to implement RequestMapping custom properties. Improve this answer. TechEnthusiast 1, 1 1 gold badge 13 13 silver badges 29 29 bronze badges. Thanks for adding your comment as an answer xwoker.

    Up to now is the best one. I have implemented the solution based on the links you mentioned and it's not that bad. The biggest problem will manifest when upgrading to a new version of Spring as it will require to check any changes to the logic behind mvc:annotation-driven. Hopefully Spring will provide a version of mvc:annotation-driven in which one can define custom conditions. Augusto, half a year later, how has this been working out for you? Also, I'm curious, are you really versioning on a per-method basis?

    SanderVerhagen it's working, but we do version the whole API, not per method or controller the API is quite small as it's focused on one aspect of the business. Unfortunately, this doesn't play nice with Swagger, as a lot of auto configuration is turned off when extending WebMvcConfigurationSupport. I tried this solution but its actually not working with 2. Do you have some example project to show? Show 1 more comment.

    Version Number Anti-Patterns - DZone Java

    Jens 1, 12 12 silver badges 30 30 bronze badges. Benjamin M Benjamin M I changed the int[] into String[] to allow versions like "1. Yes, that's pretty reasonable. For future projects, I'd go a different way for some reasons: 1. URLs represent resources. Using a URL parameter, i. I'm still not sure if I'd go with option 2 or 3 , but I will never use 1 again for reasons mentioned above. Otherwise you will encounter weird problems I suddenly had problems with Hibernates lazy initialization because of a closed session — stuXnet Jan 22 '16 at The approach looks good but somehow seems it doesn't work with junti test cases SpringRunner.

    Any chance that you have got the approach working with test cases — JDev Jul 7 '17 at This worked for me see stackoverflow. Fr Aug 29 '17 at Show 4 more comments. For example you can have a controller that contains only method stabs with version handling.

    Spring project versioning

    Add a comment. Let's say we have v1 and v2 versions for the User controller: package com. Api; import io. ApiOperation; import org. M : A 'milestone' release. RC : A 'GA release candidate'.

    What we will demonstrate

    Again, produced using the same release process. Order matters Notice that the following sequence of versions is in ordered ascending both alphabetically and toward GA: 1. Version You will notice that build scripts using the shared Gradle sources typically contain import org. Take a look at this class and its tests for details. See Also: Community download page Synchronize with maven central Springsource maven repositories. Pages You signed in with another tab or window.