0
当我在eclipse中使用Wildfly服务器在本地运行项目时,我能够访问这些模板。但是,当我在prod服务器上运行它时,它无法找到模板。VelocityEngine:找不到模板资源
我的VM模板坐在一个包:com.email.templates
我已检查WEB-INF文件夹,我可以看到,模板坐在:
myapp.war\WEB-INF\classes\com\email\templates\
我初始化我的VelocityEngine具有以下属性:
Properties prop = new Properties();
prop.put(RuntimeConstants.RESOURCE_LOADER, "class");
prop.put("class.resource.loader.class", ClasspathResourceLoader.class.getName());
this.velocityEngine.init(prop);
当试图获取t时,我试过以下两种方法下摆模板:
通过org.springframework.ui.velocity.VelocityEngineUtils
Map<String, String> model = new HashMap<String, String>();
model.put("payload", "some payload");
String body = VelocityEngineUtils.mergeTemplateIntoString(this.velocityEngine , "/com/email/templates/my_template.vm", model);
通过org.apache.velocity.app.VelocityEngine
StringWriter writer = new StringWriter();
VelocityContext context = new VelocityContext();
context.put("payload", "some payload")
Template template = this.velocityEngine.getTemplate("/com/email/templates/my_template.vm");
template.merge(context, writer);
是否使用'Maven'? 。看起来你的路径不正确。 – soorapadman
我添加了prop.setProperty(“runtime.log.logsystem.class”,“org.apache.velocity.runtime.log.CommonsLogLogChute”)。这似乎解决了这个问题。 – Fabii