我按照示例中所示的说明来渲染速度模板:
public static void main(final String[] args) {
get(new VelocityRoute("/hello") {
@Override
public Object handle(final Request request, final Response response) {
Map<String, Object> model = new HashMap<>();
model.put("hello", "Velocity World");
model.put("person", new Person("Foobar"));
// The wm files are located under the resources directory
return modelAndView(model, "hello.wm");
}
});
}
但速度似乎没有找到我的模板:
ERROR spark.webserver.MatcherFilter -
org.apache.velocity.exception.ResourceNotFoundException: Unable to find resource 'hello.wm'
at org.apache.velocity.runtime.resource.ResourceManagerImpl.loadResource(ResourceManagerImpl.java:474) ~[velocity-1.7.jar:1.7]
at org.apache.velocity.runtime.resource.ResourceManagerImpl.getResource(ResourceManagerImpl.java:352) ~[velocity-1.7.jar:1.7]
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1533) ~[velocity-1.7.jar:1.7]
at org.apache.velocity.runtime.RuntimeInstance.getTemplate(RuntimeInstance.java:1514) ~[velocity-1.7.jar:1.7]
at org.apache.velocity.app.VelocityEngine.getTemplate(VelocityEngine.java:373) ~[velocity-1.7.jar:1.7]
at spark.template.velocity.VelocityRoute.render(VelocityRoute.java:117) ~[spark-template-velocity-1.0.jar:na]
at spark.TemplateViewRoute.render(TemplateViewRoute.java:43) ~[spark-core-1.1.1.jar:na]
at spark.webserver.MatcherFilter.doFilter(MatcherFilter.java:140) ~[spark-core-1.1.1.jar:na]
at spark.webserver.JettyHandler.doHandle(JettyHandler.java:54) [spark-core-1.1.1.jar:na]
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:179) [jetty-server-9.0.2.v20130417.jar:9.0.2.v20130417]
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:136) [jetty-server-9.0.2.v20130417.jar:9.0.2.v20130417]
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:97) [jetty-server-9.0.2.v20130417.jar:9.0.2.v20130417]
at org.eclipse.jetty.server.Server.handle(Server.java:451) [jetty-server-9.0.2.v20130417.jar:9.0.2.v20130417]
at org.eclipse.jetty.server.HttpChannel.run(HttpChannel.java:252) [jetty-server-9.0.2.v20130417.jar:9.0.2.v20130417]
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:266) [jetty-server-9.0.2.v20130417.jar:9.0.2.v20130417]
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.run(AbstractConnection.java:240) [jetty-io-9.0.2.v20130417.jar:9.0.2.v20130417]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:596) [jetty-util-9.0.2.v20130417.jar:9.0.2.v20130417]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:527) [jetty-util-9.0.2.v20130417.jar:9.0.2.v20130417]
at java.lang.Thread.run(Thread.java:744) [na:1.7.0_51]
我不确定问题是什么。我试图玩弄速度,但它似乎永远找不到我的模板。
有关信息,这是我的项目的样子:
project-root
| src/main/java
| | com.stackoverflow.my-spark-app
| | | SparkMain.java
| | | Person.java
| src/main/resources
| | | hello.wm
| pom.xml