aspose file tools
The moose likes Spring and the fly likes How is the url mapping resolved? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Application Frameworks » Spring
Reply Bookmark "How is the url mapping resolved?" Watch "How is the url mapping resolved?" New topic
Author

How is the url mapping resolved?

james frain
Ranch Hand

Joined: Apr 06, 2011
Posts: 34
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?
Mark Spritzler
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 16624

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.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
 
 
subject: How is the url mapping resolved?
 
Threads others viewed
HTTP Status 404 - Servlet springtest is not available
Using Handler Mappings
Problem in spring sample application
Localisation errors
Error: spring-servlet.xml
IntelliJ Java IDE

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture