【问题标题】:Velocity Template Not Found未找到速度模板
【发布时间】:2012-10-05 23:01:27
【问题描述】:

我正在尝试在我的 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", "nik.estep@gmail.com");
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 中,因为那不是该文件夹中的内容,并且必须有一种方法可以使其工作。任何帮助将不胜感激,我昨天在试图解决这个问题时失去了一切。

【问题讨论】:

    标签: java spring spring-mvc velocity


    【解决方案1】:

    只要您的战争不是以爆炸形式部署的,就没有适合您的文件 URL。 我会尝试配置:

    http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/view/WebappResourceLoader.html

    代替文件资源加载器并使用从战争根目录开始的完整路径

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-20
      • 1970-01-01
      • 1970-01-01
      • 2013-06-10
      • 2022-08-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多