PDA

View Full Version : Shared VelocityEngine instance


Patrick Bourke
Jun 9th, 2005, 02:05 PM
I'm having trouble configuring a VelocityEngine instance which is shared between my parent and web application contexts.

In my parent context, I have defined "velocityEngine." This bean is used for composing emails and pulls templates from the classpath:

<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFact oryBean">
<property name="resourceLoaderPath">
<value>classpath:com/company/app</value>
</property>
</bean>

In the error servlet of my web app, I have defined "errorVelocityConfig" for presenting an error screen. I'd like this bean to pull templates from the WAR:

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

<bean id="viewResolver" class="org.springframework.web.servlet.view.velocity.Velo cityViewResolver">

<property name="contentType">
<value>text/xml</value>
</property>
<property name="prefix">
<value></value>
</property>
<property name="suffix">
<value>.vm</value>
</property>
</bean>

When the error page is visited through the browser, the following error appears in the logs:

2005-06-09 11:37:43,018 DEBUG [org.springframework.ui.velocity.SpringResourceLoa der] Looking for Velocity resource with name [error.vm]
2005-06-09 11:37:43,018 DEBUG [org.springframework.ui.velocity.SpringResourceLoa der] Could not find Velocity resource: class path resource [com/company/app/error.vm]
2005-06-09 11:37:43,018 ERROR [org.apache.velocity.app.VelocityEngine] ResourceManager : unable to find resource 'error.vm' in any resource loader.

I looks like VelocityConfigurer is not overriding the "resourceLoaderPath".

I've had this working in the past using two different VelocityEngine instances. In fact, everything works fine if the "velocityEngine" property is removed from the VelocityConfigurer. I was attempting to eliminate the duplicated VelocityEngine instances from the app when I ran into this issue.

How have others worked around this problem?

Thanks,
Patrick