I'm switching my apps from spring mvc to use with spring boot. To do that, i've build small projects spring mvc and spring-boot like examples.

I found what seems to be a bug with endpoint path at root context path of dispatcher. Defining a simple RestController without RequestMapping. When i call request on that, there is a 404 response

POST http://localhost:8080/api HTTP/1.1 404

But, when i add "/" at the end of request, all is good

POST http://localhost:8080/api/ HTTP/1.1 204

The good request is "POST http://localhost:8080/api", isn't it ?

All others requests are ok (like /api/sub or /api/two/other)

when debugging this problem, i realized that the problem could be

https://github.com/spring-projects/spring-framework/blob/7c982511426eebea3d34730ab128bb39a55a9de6/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java#L236

if replace this line with if (null != rest) { all request are now good

Or here : defaut path must be "/" not "" ? https://github.com/spring-projects/spring-framework/blob/7c982511426eebea3d34730ab128bb39a55a9de6/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java#L358

To reproduce : - spring mvc - spring-boot

Examples are with multiple dispatcher, but problem occurred with one dispatcher

spring 5.2.10.RELEASE spring boot 2.3.5.RELEASE

Comment From: dPechman42

I made these changes to your code and it is working now AppController.java

  @PostMapping("/api")
  public ResponseEntity<Void> postIt(final HttpServletRequest request) {
    return ResponseEntity.noContent().build();
  }

  @GetMapping("/api")
  public ResponseEntity<Void> getIt(final HttpServletRequest request) {
    return ResponseEntity.noContent().build();
  }

  @PostMapping("/api/{id}")
  public ResponseEntity<Void> post(final HttpServletRequest request) {
    return ResponseEntity.noContent().build();
  }

  @GetMapping("/api/{id}")
  public ResponseEntity<Void> get(final HttpServletRequest request) {
    return ResponseEntity.noContent().build();
  }

ApiInitializer.java

  protected String[] getServletMappings() {
    return new String[]{"/*"};
  }

OtherController.java

  @PostMapping("/other")
  public ResponseEntity<Void> postOther(final HttpServletRequest request) {
    return ResponseEntity.noContent().build();
  }

  @GetMapping("/other")
  public ResponseEntity<Void> getOther(final HttpServletRequest request) {
    return ResponseEntity.noContent().build();
  }

Comment From: Fyro-Ing

Yes "of course", but i don't want context in "@***Mapping"

On my app, i use same Controller for 2 context (/api & /backoffice as example) but security & others applied on that context are different. All is ok, only endpoint on root context path are ko

Comment From: bclozel

Sorry for getting back to you after so long. The sample application has an invalid setup: it's got multiple @SpringBootApplication classes and multiple DispatcherServlet registrations with the same configurations. It's not clear what you're trying to achieve and this point and this does not look like a Spring Framework issue.

Comment From: Fyro-Ing

@bclozel i linked on the line caused bug and this is a spring issue

if (!"".equals(rest)) {

this not the same configuration on sample, context path is different I try to reuse same controller, on multiple context, to apply business from context