Let's say I have the following controller with its parent class:
@RestController public class BusinessController extends RootController { @GetMapping(value = "users", produces = {"application/json"}) @ResponseBody public String users() { return "{ \"users\": [] }" } @GetMapping(value = "companies", produces = {"application/json"}) @ResponseBody public String companies() { return "{ \"companies\": [] }" } } @RestController @RequestMapping(path = "api") public class RootController { } Data is retrieved by calling such URL's:
http://app.company.com/api/users http://app.company.com/api/companies Now let's say I want to rename the /api path to /rest but keep it "available" by returning a 301 HTTP status code alongside the new URI's
e.g. client request:
GET /api/users HTTP/1.1 Host: app.company.com server request:
HTTP/1.1 301 Moved Permanently Location: http://app.company.com/rest/users So I plan to change from "api" to "rest" in my parent controller:
@RestController @RequestMapping(path = "rest") public class RootController { } then introduce a "legacy" controller:
@RestController @RequestMapping(path = "api") public class LegacyRootController { } but now how to make it "rewrite" the "legacy" URI's?
That's what I'm struggling with, I can't find anything Spring-related on the matter, whether on StackOverflow or elsewhere.
Also I have many controllers AND many methods-endpoints so I can not do this manually (i.e. by editing every @RequestMapping/@GetMapping annotations).
And project I'm working on is based on Spring Boot 2.1
Edit: I removed the /business path because actually inheritance doesn't work "by default" (see questions & answers like Spring MVC @RequestMapping Inheritance or Modifying @RequestMappings on startup ) - sorry for that.
@SpringBootApplicationand a bunch of other ones with traditional Spring's@Configurationwhich provide a few@Beanor@Component; only 1 of them is thepublic class SecurityConfig extends WebSecurityConfigurerAdapterto customize Spring Security.