Alex Pi
Alex Pi

Reputation: 826

Chaining spring view resolvers

Is there an alternative way to achieve the next behavior in spring?:

Given path xxx/yyy

1) Look up for static/html/xxx/yyy.html

2) In case html doesn't exist look up for WEB-INF/xxx/yyy.jsp

I was trying the next config. But it seems UrlBasedViewResolver fails and doesn't delegate to the next ViewResolver.

So it seems u can't actually chain two UrlBasedViewResolver in Spring, am I right?

<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/" />
    <property name="suffix" value=".jsp" />
    <property name="order" value="1" />
</bean>          

<bean id="htmlViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix" value="/static/html/" />
    <property name="suffix" value=".html" />
    <property name="order" value="0" />
</bean>

Any help would be appreciated.

Cheers.

Upvotes: 2

Views: 1859

Answers (1)

jelies
jelies

Reputation: 9290

As you say, you can't, because UrlBasedViewResolver (or InternalResourceViewResolver) always resolves the view and is not possible to delegate to next ViewResolver. Reference says that this kind of ViewResolver always need to be the last.

There are some workarounds that may help you, as implementing your custom ViewResolver.

Upvotes: 3

Related Questions