Thursday, August 11, 2011

Integrating Spring with Velocity

you need to download velocity jar and add it to ur project's classpath and WEB-INF/lib folder

you will need to add below mappings to ur spring servlet

<!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory -->
    <beans:bean name ="viewResolver" class="org.springframework.web.servlet.view.velocity.VelocityViewResolver">
        <beans:property name="prefix" value="" />
        <beans:property name="suffix" value=".vm" />
   <!--     <beans:property name="exposeSpringMacroHelpers" value="true"/> -->    
    </beans:bean>

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

be careful with below 3 values. These should be according to your project setup.

<beans:property name="prefix" value="" />
        <beans:property name="suffix" value=".vm" />
<beans:property name="resourceLoaderPath" value="/WEB-INF/velocity/" />



you should have a velocity file in your velocity folder, i have a file named home.vm. set up ur web.xml and it should work.

If more detailed explanation is needed, let me know.









No comments:

Post a Comment