• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

How is the url mapping resolved?

Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Have been following what I consider to be a very good worked spring example here http://static.springsource.org/spring/articles/2005/MVC-step-by-step/Spring-MVC-step-by-step-Part-1.html
Have a couple of questions.
When the container sees the request "Hello.htm" it matches this with the Spring mapping

in web.xml and creates the springapp context. What I don't understand is how does the container know to build the spring context using the file springapp-servlet.xml? Is this as simple as, the servlet name is springapp so there should be a file called springapp-servlet.xml I can use to build the context to service this request? If so, is this a "Spring framework"thing ?

Q2, when the springapp-servlet.xml context is loaded, it appears the framework then finds the type of class to service the request based on looking at the following mappings in springapp-servlet.xml.

So I modified the urlMapping id to id="MickyMouse" and it still worked so what kind of voodoo is going on where by the framework knows to magically pluck the classname springappController out of the list of mappings in this particular bean definition?
Posts: 17347
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1) Just a naming convention that uses the Servletname-servlet.xml. But you can set an init-param to the DispatcherServlet if your config file is a different name and/or in different locations.
2) The id of the bean SimpleUrlMappingHandler has no meaning at all in mapping. Notice the prop key="xxx" what goes in there is what is mapped. A MappingHandler class is simply a class that the DispatcherServlet delegates looking at the URL to determine which Controller to call. You can actually register more than one MappingHandler, and the Request will be passed to all of them and the first that says they understand the URL and what Controller to call, calls it.

There are many times that you are registering a bean/class that is a Spring class that you want to help set up some api/technology, but not a bean that you as a developer need an id to ref or call getBean on. And the SimpleUrlMappingHandler is one of those. Once Spring sees you have a bean of that class which implements the MappingHandler interface, it will create an instance and put it in its correct place.

Bras cause cancer. And tiny ads:
a bit of art, as a gift, that will fit in a stocking
    Bookmark Topic Watch Topic
  • New Topic