config file:
// import org.apache.velocity.app.VelocityEngine;
@Bean
public VelocityEngine velocityEngine() {
final VelocityEngine velocityEngine = new VelocityEngine();
velocityEngine.setProperty("resource.loader", "class");
velocityEngine.setProperty("class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader");
return velocityEngine;
}
locally everything is fine but when I deploy my app to Heroku I catch that exception:
velocityEngine.getTemplate("./templates/template_1.html");
Exception:
ResourceNotFoundException
Unable to find resource './templates/template_1.html'
You need to use velocityEngine.getTemplate("templates/template_1.html")
, as an absolute/file system based path like ./templates/template_1.html
wouldn't exist after the application has been packaged into a jar file or docker image. You can find the sample app in github
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.