繁体   English   中英

Velocity 2.0无法在jar中找到模板资源

[英]Velocity 2.0 unable to find template resource in jar

我在Spring Boot 5中使用Velocity 2.0来发送电子邮件。 我从src / main / resources / email /加载模板并将VelocityEngine定义为config.xml文件中的bean

<bean id="velocityEngine" class="org.apache.velocity.app.VelocityEngine">
    <property name="properties">
        <props>
            <prop key="resource.loader">file</prop>
            <prop key="file.resource.loader.class">org.apache.velocity.runtime.resource.loader.FileResourceLoader</prop>
            <prop key="file.resource.loader.path">src/main/resources/templates/email/</prop>
            <prop key="file.resource.loader.cache">true</prop>
            <prop key="file.resource.loader.modificationCheckInterval">5</prop>
        </props>
    </property>
</bean>

当我从Intellij IDEA中运行它时,一切正常,但是当我构建jar以在服务器上运行它时,它会抛出异常:org.apache.velocity.exception.ResourceNotFoundException:无法找到资源'MyTemplate.vm'。 知道如何解决吗? 我将不胜感激

因此,您正在使用FileResourceLoader并为其指定相对路径“ src / main / resources / templates / email /”

因此,除非相对于您的应用程序运行位置的路径在服务器上,否则它会为您提供完全合理的错误代码。

您想在bean配置中使用ClasspathResourceLoader并确保模板正确打包在生成的jar中,这是您想要做的。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM