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?

Alparslan
  • 13
  • 3
  • Maybe that would be a solution? https://stackoverflow.com/questions/2513031/how-to-use-multiple-requestmapping-annotations-in-spring Then you could just keep you old Controller Methods but add an additional mapping. – Benjamin Eckardt Jul 18 '20 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! – Alparslan Jul 20 '20 at 00:38
  • Only other solution that I can think of is doing it programmatically but that won't make it any better. Sorry. – Benjamin Eckardt Jul 20 '20 at 07:32

0 Answers0