In this tutorial Spring DispatcherServlet is configured using the spring-servlet.xml file, this one:
In this file I am using the context:component-scan tag to say that Spring have to scan my file serching the annotation, so for exemple, when in the controller class find that a method is annoted by @RequestMapping("/hello") annotation know that this method handle the HTTP Request toward the URL ending with "/hello". This is simple...
Now my doubt is related to the Spring MVC template project that I could automatically build in STS\Eclipse
When I create a new Spring MVC project in STS I have that my DispatcherServlet is configured by a file named servlet-context.xml that contains some configuration similar to the previus example file.
In this file, I still have the component scan tag:
but I have also another tag (that look like have similar task), this one:
What is the difference between these two tags? between these two tags?
An other "strange" thing is that the previus example (that don't use the annotation-driven tag) is very very similar to the project create by STS using the Spring MVC Template project but if I delete the annotation-driven tag from its configuration file the project don't run and give me the following error: HTTP Status 404 -
And in the stacktrace I have:
WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/maventestwebapp/] in DispatcherServlet with name 'appServlet'
But why? In the previus example work well without annotation-driven tag, and this controller class is very similar...infact have only one method that handles HTTP request toward "/" path