The project (SpringBoot 2+, thymeleaf) has a simple restore controller of the form:

@RestController public class Controller { @GetMapping ("/index") public String index() { return "Hellow"; } 

If you run in this form, then the request to localhost:8080/index processed normally, all that except this address does not pass (for example, localhost:8080/index/ - will give 404). But if you hang an annotation on the class:

 @RestController ("/index") public class Controller { @GetMapping public String index() { return "Hellow"; } 

That requests are processed incorrectly - for all requests, localhost:8080/index/ , localhost:8080/ , even garbage addresses on which there is no mapping - localhost:8080/qqqqqq ) - return instead of 404 - "Hellow".

Why? Why in the second case all requests to the application go to this controller, although I set the mapping to a specific context ("/ index")?

    2 answers 2

    Because mapping is not placed on @RestController, but on @RequestMapping or the like (@GetMapping, @PostMapping ...)

      The answer is here https://www.baeldung.com/spring-controller-vs-restcontroller and here https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web /bind/annotation/RestController.html . In short, the name of the logical component is indicated in parentheses for @RestController (), and not the url pattern.