2012-10-05 162 views
0

我想在我的Spring MVC网站中使用Velocity来模板化电子邮件。我相信如果Velocity能找到我想使用的模板,一切都会好的。我在/WEB-INF/emails/faultNotification.vm有一个模板。在我的代码,我有这样的:速度模板未找到

MimeMessageHelper helper = new MimeMessageHelper (message, true); 
helper.setTo (toAddresses); 
helper.setSubject (subject); 
Map<String, Object> model = new HashMap<>(); 
model.put ("username", "nikitin"); 
model.put ("emailAddress", "[email protected]"); 
helper.setText (VelocityEngineUtils.mergeTemplateIntoString (
           m_emailEngine, 
           "faultNotification.vm", 
           model), true); 
helper.addAttachment (attachmentName, 
         new ByteArrayResource (attachment.toByteArray()), 
         "application/zip"); 
m_sender.send (message); 

在我的XML,我有这样的:

<bean id="velocityEngine" class="org.springframework.ui.velocity.VelocityEngineFactoryBean"> 
     <property name="resourceLoaderPath" value="file:/WEB-INF/emails" /> 
</bean> 
<bean id="emailSender" class="com.tarigma.gem.communication.EmailSender"> 
    <constructor-arg ref="systemSettings" /> 
    <constructor-arg ref="velocityEngine" /> 
</bean> 

我一直在阅读任何文章中,我可以找到,从我所知道的,这应该工作,但是当我去使用它时,Velocity找不到模板(ERROR VelocityEngine - ResourceManager: Unable to find resource 'faultNotification.vm' in any resource loader)。我不想将该模板放在/WEB-INF/classes中,因为这不是该文件夹中的内容,因此必须有一种方法才能完成此项工作。任何帮助将不胜感激,我昨天失去了所有试图解决这个问题。

回答