• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

[MVC]Why in this example I have to use annotation-driven tag? Difference beetwen component-scan

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Some days ago I begin to study this Spring Hello World Tutorial: http://viralpatel.net/blogs/spring-3-mvc-create-hello-world-application-spring-3-mvc/

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

This is the code of my controller class:


Can someone help me to understand this thing?

Thank you very much

Andrea
 
Bartender
Posts: 1682
7
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please have a look at this thread.
https://coderanch.com/t/586286/Spring/mvc-annotation-driven-context-annotation
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic