0

In our REST APIs, we want to use path-based versioning for REST endpoints. Let's say we have a /v1/students GET endpoint. We have a corresponding controller method like:

@GetMapping("/v1/students")
public List<Student> getStudents(){
   return studentService.getStudents();
}

Inside a controller class called SchoolControllerV1.java (along with 20 different other endpoints.) And months later we have a breaking change in response structure and we need a new version like /v2/students GET.

@GetMapping("/v2/students")
public List<StudentV2> getStudents(){
   return studentService.getStudentsV2();
}

Inside a controller class called SchoolControllerV2.java (along with 20 different other endpoints.) The problem is the other 19 controller methods which are exactly identical in V1 and V2 controllers are duplicated.

What is the best way of having multiple versions of controllers on a Spring Boot application?

3
  • Maybe that would be a solution? stackoverflow.com/questions/2513031/… Then you could just keep you old Controller Methods but add an additional mapping. Commented Jul 18, 2020 at 21:20
  • yeah @BenjaminEckardt the actual solution I use is just like that. Looking for a better alternative if exists. Thank you by the way! Commented Jul 20, 2020 at 0:38
  • Only other solution that I can think of is doing it programmatically but that won't make it any better. Sorry. Commented Jul 20, 2020 at 7:32

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.