Announcement Announcement Module
Collapse
No announcement yet.
Shared VelocityEngine instance Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Shared VelocityEngine instance

    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:

    Code:
    <bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
          <property name="resourceLoaderPath">
             <value>classpath&#58;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:

    Code:
    <bean id="errorVelocityConfig"
    		class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
    		<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.VelocityViewResolver">
    
    		<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:

    Code:
    2005-06-09 11&#58;37&#58;43,018 DEBUG &#91;org.springframework.ui.velocity.SpringResourceLoader&#93; Looking for Velocity resource with name &#91;error.vm&#93;
    2005-06-09 11&#58;37&#58;43,018 DEBUG &#91;org.springframework.ui.velocity.SpringResourceLoader&#93; Could not find Velocity resource&#58; class path resource &#91;com/company/app/error.vm&#93;
    2005-06-09 11&#58;37&#58;43,018 ERROR &#91;org.apache.velocity.app.VelocityEngine&#93; ResourceManager &#58; 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
Working...
X