Every Controller class can have one default request mapping method. What is the default request mapping method? If we simply don't specify any request path value
in the @RequestMapping
annotation of a Controller's method, that method is designated as the default request mapping method for that class. So whenever a request URL just ends up with the Controller's class level request path value without any further relative path down the line, then Spring MVC will invoke this method as a response to that request.
Tip
If you specify more than one default mapping method inside a Controller, you will get IllegalStateException
with the message Ambiguous mapping found. So a Controller can have only one default request mapping method at most.
Why not change the welcome
method to the default request mapping method for our HomeController
class?
In the
HomeController
class, add the following annotation on top of the class:@RequestMapping("/")
And from the
welcome...