The*_*boy 1 java spring velocity
我正在使用Spring MVC作为我的Web应用程序,我正在整合Velocity来模拟我的电子邮件.
当它尝试发送我的电子邮件时,我收到以下500错误.
org.apache.velocity.exception.ResourceNotFoundException:
Unable to find resource '/WEB-INF/velocity/registrationEmail.vm'
Run Code Online (Sandbox Code Playgroud)
我知道这意味着什么,我需要做什么,但我知道我一定做错了,我无法弄清楚为什么它找不到我的.vm文件.
我在applicationContext.xml文件中配置了如下速度,但我相信我可能会留下Velocity需要查找文件的必要属性.
<bean id="velocityEngine"
class="org.springframework.ui.velocity.VelocityEngineFactoryBean">
<property name="velocityProperties">
<value>
resource.loader=class
class.resource.loader.class=
org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader
</value>
</property>
</bean>
<bean id="velocityConfig" class="org.springframework.web.servlet.view.velocity.VelocityConfigurer">
<property name="resourceLoaderPath" value="/WEB-INF/velocity/"/>
</bean>
Run Code Online (Sandbox Code Playgroud)
我相信这可能是我需要进行一些更改/添加的地方,但我不确定.
我的模板文件的路径是WEB-INF/velocity/templateName.vm
我在控制器中使用velocityEngine bean时也指定了这个,如下所示
String text = VelocityEngineUtils.mergeTemplateIntoString(
velocityEngine, "/WEB-INF/velocity/registrationEmail.vm", test);
我的build.xml文件中是否需要执行某些操作以确保它能够找到我的模板文件?
我认为问题是WEB-INF不是CLASSPATH的一部分.您不能指望ClasspathResourceLoader找到CLASSPATH中没有的东西.
WEB-INF/classes和WEB-INF/lib中的所有JAR都在CLASSPATH中.尝试使用WEB-INF/classes下的.vm文件移动文件夹,看看是否有帮助.
最好的想法是遵循Spring文档:
http://static.springsource.org/spring/docs/2.5.x/reference/view.html#view-velocity
| 归档时间: |
|
| 查看次数: |
23509 次 |
| 最近记录: |