It Can ApiVersioning Easier With Annotation
Must Express Position of API Version With {version}
@RequestMapping("/service/api/{version}/")
It's Possible ApiVersioning Both Class Level RequestMapping And Method RequestMapping
@Controller
@RequestMapping("/service/api/")
public class ApiController {
// /service/api/v2/test
@ApiVersion(version = Version.V2)
@RequestMapping(value = "/{version}/test", method = {RequestMethod.GET, RequestMethod.POST})
public String testv2(HttpServletRequest httpReq, Model model) throws Exception{
System.out.println("testv2");
return "test";
}
}
If You Declare Class And Method Both Then Class Declare is Ignored. Method Annotation is Priority First.
@Controller
@RequestMapping("/service/api/{version}/")
@ApiVersion(version = Version.V3)
public class ApiTobeController {
// /service/api/v3/test
@RequestMapping(value = "/test", method = {RequestMethod.GET, RequestMethod.POST})
public String testv3(HttpServletRequest httpReq, Model model) throws Exception{
return "test";
}
// /service/api/v4/test
// /service/api/v5/test
@ApiVersion(version = {Version.V4, Version.V5})
@RequestMapping(value = "/{version}/test", method = {RequestMethod.GET, RequestMethod.POST})
public String testv45(HttpServletRequest httpReq, Model model) throws Exception{
return "test";
}
}
It's Possible Create Multiple Version UrlMapping
@ApiVersion(version = {Version.V4, Version.V5})
@RequestMapping(value = "/{version}/test", method = {RequestMethod.GET, RequestMethod.POST})
public String testv45(HttpServletRequest httpReq, Model model) throws Exception{
return "test";
}