Velocity 郵件模板在Spring 中發(fā)郵件報(bào)unable to find resource 'WEB-INF/test.vm' in any resource loader導(dǎo)常。配置如下:
<bean id="templateMail" class="com.chenlb.mail.VelocityTemplateMessage">
<property name="javaMailSender" ref="mailSender"></property>
<property name="from" value="${mail.from}"></property>
<property name="encoding" value="UTF-8"></property>
<property name="templateLocation" value="WEB-INF/test.vm"></property>
<property name="velocityEngine">
<bean class="org.springframework.ui.velocity.VelocityEngineFactoryBean"></bean>
</property>
<property name="title" value="www.tkk7.com/chenlb"></property>
</bean>
郵件內(nèi)容生成如下:
VelocityEngineUtils.mergeTemplateIntoString(velocityEngine, templateLocation, encoding, model);
但導(dǎo)常,說(shuō)不可用的資源。
說(shuō)明:VelocityEngineUtils.mergeTemplateIntoString()里的templateLocation的文件,不會(huì)像Spring一樣找。然后就看Spring 的 VelocityEnginFactory API和試,最后發(fā)現(xiàn)
<bean class="org.springframework.ui.velocity.VelocityEngineFactoryBean"></bean>
單獨(dú)定義,并配置resourceLoaderPath屬性即可搞定。
配置后的:
<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="resourceLoaderPath" value="WEB-INF/"></property>
</bean>
<bean id="templateMail" class="com.chenlb.mail.VelocityTemplateMessage">
<property name="javaMailSender" ref="mailSender"></property>
<property name="from" value="${mail.from}"></property>
<property name="encoding" value="UTF-8"></property>
<property name="templateLocation" value="test.vm"></property>
<property name="velocityEngine" ref="velocityEngine"></property>
<property name="title" value="wwww.tkk7.com/chenlb"></property>
</bean>
resourceLoaderPath是由Spring設(shè)置過(guò)的,跟平常的(Spring)文件資源一樣方式引用,Spring真的太方便了。
posted on 2007-08-18 02:11
流浪汗 閱讀(3739)
評(píng)論(0) 編輯 收藏 所屬分類:
OpenSource