Digging deeper...
I had to write my own Dispatcher servlet to be able to specify which resolver bean name to use.
I woudn't have had to do that if org.springframework.web.servlet.DispatcherServlet. VIEW_RESOLVER_BEAN_NAME wasn't just a private constant, but rather something configurable.
Code:
public class MyDispatcherServlet extends
org.springframework.web.servlet.DispatcherServlet {
protected String viewResolverName = null;
protected ViewResolver namedViewResolver = null;
/**
*
*/
public MyDispatcherServlet() {
super();
}
/**
* Initialize the specific view resolver used by this class.
*/
private void initNamedResolver(ApplicationContext context) {
try {
this.namedViewResolver = (ViewResolver) context.getBean(
getViewResolverName(), ViewResolver.class);
} catch (NoSuchBeanDefinitionException ex) {
// Ignore, we'll add a default ViewResolver later.
}
}
/**
* Try to used the specified view resolver.
*/
protected View resolveViewName(String viewName, Map model, Locale locale,
HttpServletRequest request) throws Exception {
View view = null;
if (this.namedViewResolver != null) {
view = this.namedViewResolver.resolveViewName(viewName, locale);
}
if (view != null) {
return view;
} else {
return super.resolveViewName(viewName, model, locale, request);
}
}
/**
* Initialize the strategy objects that this servlet uses.
*/
protected void initStrategies(ApplicationContext context) {
super.initStrategies(context);
initNamedResolver(context);
}
public String getViewResolverName() {
return viewResolverName;
}
public void setViewResolverName(String viewResolverName) {
this.viewResolverName = viewResolverName;
}
}
Now that I have that setup, I just had to add an init parameter in my web.xml to specify which "viewResolverName" to use. This init param automatically fills in the corresponding property of the servlet. Pretty cool.
Sure enough, One servlet uses one viewResolver and another servlet uses a different view resolver.
Still have a problem.
One viewResolver has the normal Spring JSTLView class set:
Code:
<bean id="pageViewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix">
<value>/WEB-INF/jsp/page/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
but the other has a class I've overridden called "XMLJSTLView".
The only difference is that my XML subclass overrides the getContentType() to return "text/xml".
The problem is, that while the new view class is being used, getContentType() never gets called, and the browser is still getting "text/html" !
This really shouldn't be this difficult.