简体   繁体   English

速度模板资源未找到异常

[英]velocity template resource not found exception

Exception occurred: org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'ResourceLoader1.vm' 发生异常:org.apache.velocity.exception.ResourceNotFoundException:无法找到资源“ ResourceLoader1.vm”

I am having ResourceLoader1.vm in /WEB-INF/templates, I stuck up with this please help me. 我在/ WEB-INF / templates中有ResourceLoader1.vm,我坚持使用此功能,请帮助我。

            Properties props = new Properties();  
            props.put("file.resource.loader.path", "/WEB-INF/templates");
            Velocity.init(props);
            VelocityContext context = new VelocityContext();
            context.put("greetings", "Many Happy returns");
            context.put("name", "Joseph");
            Writer writer = new StringWriter();
            Template template = Velocity.getTemplate("ResourceLoader1.vm");
            template.merge(context, writer);

You should put .vm templates relative to the CLASSPATH. 您应该将.vm模板相对于CLASSPATH。 A better choice would be to put the /templates directory under WEB-INF/classes, lose the props, and fetch it like this: 更好的选择是将/ templates目录放在WEB-INF / classes下,丢失道具,并按以下方式获取它:

Template template = Velocity.getTemplate("templates/ResourceLoader1.vm");

It seems you're using Velocity in a web application. 似乎您正在Web应用程序中使用Velocity。 For this, you'd be better off using the VelocityViewServlet that's specifically designed for this kind of usage. 为此,最好使用专门为这种用法设计的VelocityViewServlet

The FileResourceLoader that's used with your configuration has no knowledge of the webserver and contexts and stuff, so the way you've configured it, it would look for a WEB-INF folder at the root of the filesystem your application server is running at. 与配置一起使用的FileResourceLoader不了解Web服务器以及上下文和内容,因此,按照配置方式,它将在运行应用程序服务器的文件系统根目录中查找WEB-INF文件夹。

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

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