Nemykin Roman opened SPR-17047 and commented

Often spring application has rest API and usually we have some controller

@RestController
@RequestMapping("/api/v1")
public class ApiController {
}

It would be greate if we could rewrite it to

@RestController(path = "/api/v1")
public class ApiController {
}

Issue Links: - #21979 Add Path to @Controller ("is duplicated by")

Comment From: bclozel

We've had a few similar requests over the years (see all linked issues above), but I'm going to close this and decline this enhancement request.

As seen in #22543, we already improved things because "empty" @RequestMapping declarations can be confusing as they don't restrict in any way which requests are mapped there. If we introduce @RestController(path="...") this means that the default value for that path attribute would be ""; as a result, the controller would be mapped on the root endpoint.

This means that for all existing controllers like this:

@RestController
@RequestMapping("/spring")
public class TestController {

  @GetMapping("/greeting")
  public String hello() {
    return "Hello";
  }
}

In theory, the greeting method would now be mapped for both "/spring/greeting" and "/greeting". This is definitely a security problem and massive upgrade problem for lots of applications out there.

We could somehow work around this case, but this goes against the entire composition logic of mappings we've followed so far and could be considered as a bug for most people.

In light of that, I'm declining this issue.