PDA

View Full Version : VelocityEngine and spring.vm


jopaki
Oct 5th, 2005, 01:07 AM
When I declare a stand-alone VelocityEngine:


<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFact oryBean">
<property name="resourceLoaderPath">
<value>/WEB-INF/views/</value>
</property>
<property name="configLocation">
<value>WEB-INF/velocity.properties</value>
</property>
</bean>



<bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.Velo cityConfigurer">
<property name="velocityEngine" ref="velocityEngine"/>
<!--<property name="resourceLoaderPath"><value>/WEB-INF/views/</value></property>-->
</bean>


as opposed to an implicit one:


<bean id="velocityConfigurer" class="org.springframework.web.servlet.view.velocity.Velo cityConfigurer">
<property name="resourceLoaderPath"><value>/WEB-INF/views/</value></property>
</bean>


spring.vm is not picked up by the VelocityConfigurer.

So how do I now coerce the VelocityConfigurer to add the spring.vm macros to the "independent" velocity engine?

thanks.

davison
Oct 5th, 2005, 04:27 AM
the problem is that when you manually set the VelocityEngine on the configurer, the configurer doesn't automatically post-process the instance to add the macro support. When you use configurer to create the VelocityEngine, this method does get called.

You can set the following properties on your engine manually (untested):

springMacro.resource.loader.class=org.apache.veloc ity.runtime.resource.loader.ClasspathResourceLoade r
resource.loader=YOUR_EXISTING_RESOURCE_LOADER,spri ngMacro
velocimacro.library=org/springframework/web/servlet/view/velocity/spring.vm

Ideally, I think configurer should automatically post-process the velocityEngine that you set on it to do this - which can be amended easily enough. The only tricky aspect to this is if someone is setting their own engine on a configurer as a way of explicitly NOT getting Spring macro support, this change might break their application.

If you want to raise a JIRA issue for getting that behaviour added, I'll take a look at it. Post the JIRA URL here once created and I'll pick it up.

Regards,

djhelbert
Mar 14th, 2007, 03:20 AM
<bean id="velocityConfig"
class="org.springframework.web.servlet.view.velocity.Velo cityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/velocity/" />
<property name="velocityProperties">
<props>
<prop key="velocimacro.library">org/springframework/web/servlet/view/velocity/spring.vm,VM_global_library.vm</prop>
</props>
</property>
</bean>

This configuration allows you to use existing spring.vm bundled in spring framework, plus define your own macro file in the /WEB-INF/velocity directory.