I'm porting an existing web service to Spring 3.2. I need versioned APIs and have a controller for every new version. I do not want to re-defined methods in newer Controllers and instead want to automatically map requests to old controller if it's not found in the latest.
For example, if ControllerV1
has /home
and /login
and ControllerV2
has /login
, then I want requests to be routed like this.
/home -> ControllerV1
/v1/home -> ControllerV1
/v2/home -> ControllerV1
/login -> ControllerV1
/v1/login -> ControllerV1
/v2/login -> ControllerV2
One option would be to provide multiple paths in @RequestMapping
. However, that would mean removing paths from all older controllesr whenever adding the API in a newer version. What is the most elegant way to achieve this?