Spring Framework does not restrict the developers to use only one view resolver or the url handlers. The developers can specify multiple view resolver and URL handlers and tell the Spring Framework in which order the framework has to look upon.
<bean id="simpleUrlHandlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <value> /hello.do=helloController /messageDisplay.do=messageDisplayController </value> </property> <property name="order" value="1"></property> </bean> <bean id="beanNameUrlHandlerMapping" class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping"> <property name="order" value="2"></property> </bean>
The Order property tells the Spring Framework in which order it should process the incoming URL requests.
Chaining View Resolvers:
Spring Framework provides different kinds of View Resolvers namely XmlViewResolver, ResourceBundleViewResolver, InternalResourceViewResolver, etc that we could use for different scenarios.
The developers could use more than one view resolver and tell the Spring Framework in which order it should be used for resolving a particular view.
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/view/jsp/" /> <property name="suffix" value=".jsp" /> <property name="order" value="1"></property> </bean> <bean id="xmlViewResolver" class="org.springframework.web.servlet.view.XmlViewResolver"> <property name="order" value="2"/> <property name="location" value="views.xml"/> </bean>
No comments:
Post a Comment