Spring supports more than one view resolver. This is called chain resolving or overriding specific views in certain circumstances. Chaining view resolvers is simple just adding more than one resolver to application context and, order property can be used to specify an order. The higher the order property of view, the later the view resolver will be positioned in the chain.
Here we have chain of view resolvers consists of two resolvers:
InternalResourceViewResolver: It is always automatically positioned as the last resolver in the chain) and
XmlViewResolver: It is for specifying Excel views (which are not supported by the InternalResourceViewResolver):
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/> <property name="prefix" value="/WEB-INF/jsp/"/> <property name="suffix" value=".jsp"/> </bean> <bean id="excelViewResolver" class="org.springframework.web.servlet.view.XmlViewResolver"> <property name="order" value="1"/> <property name="location" value="/WEB-INF/simpleviews.xml"/> </bean>
<beans> <bean name="report" class="org.springframework.example.ReportExcelView"/> </beans>
If a specific view resolver does not result in a view, Spring will inspect the context to see if other view resolvers are configured. If there are additional view resolvers, it will continue to inspect them. If not, it will throw an Exception.