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