View Full Version : multiple DispatcherServlet in one project
thurm.zhang
Mar 16th, 2006, 01:26 AM
Hi *,
we have started a new project and used the SpringMVC as web framework, at present we defined over 5 DispatcherServlet in the web.xml to process each module in the project, to be honest all of the developers are newbie in SpringMVC, so we are wondering if such design is a dirty one? maybe only one DispatcherServlet per project is fairly enough? any idea is appreciated!
thanks...
br
kay
Mar 16th, 2006, 04:08 AM
Put it this way: if your modules are really big and require separate contexts, then by all means use separate DispatcherServlet's and create one xxxx-servlet.xml for each of them (they will all inherit the common applicationContext.xml so you can share your common "low-level" components there - DataSources etc.). Otherwise you can define one DispatcherServlet that handles all requests and use a SimpleUrlHandlerMapping in the servlet XML context to sort the requests into the separate modules, e.g.:
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlH andlerMapping">
<property name="mappings">
<props>
<prop key="/index.htm">startPageController</prop>
<prop key="/module1/something.htm">ModuleOneController</prop>
<prop key="/module1/*.htm">ModuleOneMultiActionController</prop>
<prop key="/module2/*.htm">ModuleTwoMultiActionController</prop>
</props>
</property>
</bean>
You get the idea. I've grown quite fond of using MultiActionControllers to handle everything that doesn't require form binding (the PetClinic sample app takes such an approach), use FormControllers for the complex forms, and potentially add some ParameterizableViewController to front any JSP pages which you would ordinarily expose directly.
vBulletin® v3.7.3, Copyright ©2000-2008, Jelsoft Enterprises Ltd.