Spring 3 MVC Multiple view resolvers(Jsp and Veloc

2019-04-17 14:21发布

Because of some business/technical constraints we should use spring3 MVC multiple view resolvers(JSP and Velocity). I tried to search on net on this but i couldn't find perfect solution. May be someone else had experienced the same scenario. So Could you please let me know is it possible to use both JSP and Velocity as vew resolvers in the SPring3 MVC application

All help is appreciated.

2条回答
霸刀☆藐视天下
2楼-- · 2019-04-17 14:47

Yes, it is possible to configure multiple view resolvers, just ensure that you order the Velocity one higher than the JSP based view resolver:

<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver" p:order="0">
  ...
</bean


<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver" p:order="1">
  <property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
  <property name="prefix" value="/WEB-INF/jsp/"/>
  <property name="suffix" value=".jsp"/>
</bean>
查看更多
We Are One
3楼-- · 2019-04-17 15:01

Spring support multiple view resolvers. You chain view resolvers by adding more than one resolver to your application context and use the order property to specify ordering.

you can use chain these jsp and velocity like -

    <bean id="viewResolver" 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"/>
      <property name="order" value="2" />
    </bean>

<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
  <property name="resourceLoaderPath" value="/WEB-INF/velocity/"/>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
  <property name="cache" value="true"/>
  <property name="prefix" value=""/>
  <property name="suffix" value=".vm"/>
  <property name="order" value="1" />
</bean>

Find out more about view chaining here

查看更多
登录 后发表回答