title: Spring REST multiple controller files per version
body: <p>In our REST APIs, we want to use <strong>path-based versioning</strong> for REST endpoints.
  Let's say we have a /v1/students GET endpoint. We have a corresponding controller method like:</p>
  <pre><code>@GetMapping(&quot;/v1/students&quot;)
  public List&lt;Student&gt; getStudents(){
     return studentService.getStudents();
  }
  </code></pre>
  <p>Inside a controller class called SchoolControllerV1.java (<strong>along with 20 different other endpoints</strong>.)
  And months later we have a breaking change in response structure and we need a new version like /v2/students GET.</p>
  <pre><code>@GetMapping(&quot;/v2/students&quot;)
  public List&lt;StudentV2&gt; getStudents(){
     return studentService.getStudentsV2();
  }
  </code></pre>
  <p>Inside a controller class called SchoolControllerV2.java (<strong>along with 20 different other endpoints</strong>.)
  The problem is the other 19 controller methods which are exactly identical in V1 and V2 controllers are duplicated.</p>
  <p>What is the best way of having multiple versions of controllers on a Spring Boot application?</p>