Hello All, These days i have started learning Spring ...i would like to know about the convention support in Spring ...for example ...suppose i have the context servlet "myApp-servlet.xml" which is the core file of Spring where we defined all the urlMappings, Dependency Injection and other stuff.. For large applications we need to define many url Mappings since there are many controllers .. Question is ..is there any mechanism (any Convention support) through which i can get rid of this huge url mapping tag ...i need to just write the controller and method name in the url and want to process it ... any idea or alternatives ............
A very good practice is to break your application context across multiple xml files. In my opinion using a unique xml file based on the servlet-name is a very poor designing decision. Especially for larger applications, maintaining a huge monolithic configuration file is only going to be a pain in the neck.
Having said that the approach I�m following is to have multiple spring-*.xml files, like spring-resources.xml, spring-hibernate.xml, etc and to have the contextConfigLocation context parameter helping with loading the beans:
Valentin is correct about splitting up your files, but dont go mad and have lots of xml files, it is as bad as having one big one. To follow on there are some other ways of splitting your files, If you are using spring mvc then in your web.xml you need to do what Valentin said to let the controling servlet know about all your xml files.
Originally posted by mudassir shahab: For large applications we need to define many url Mappings since there are many controllers .. Question is ..is there any mechanism (any Convention support) through which i can get rid of this huge url mapping tag
I'm assuming that you're concerned about how lengthy a SimpleUrlHandlerMapping can get in a large application with multiple controllers...right?
If that's your concern, then you should have a look at BeanNameUrlHandlerMapping or ControllerClassNameHandlerMapping.
BeanNameUrlHandlerMapping has been part of Spring since early on and uses the bean's name as the URL mapping. For example:
Notice that you should use the name attribute to name your bean instead of id, as the id attribute has special meaning in XML and won't allow certain characters--the name attribute is roughly equivalent to id, but doesn't have the same hang-ups with special characters.
ControllerClassNameHandlerMapping is new to Spring 2. It assumes a convention where the controller's class name is used as the URL mapping. For example, the following controller bean...