gpt4 book ai didi

java - 资源未找到异常 : for spark-java and velocity

转载 作者:行者123 更新时间:2023-12-02 06:17:18 27 4
gpt4 key购买 nike

我按照示例中所示的说明来渲染速度模板:

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

最佳答案

事实上,它对我有用。我使用速度模板引擎创建了一个简单的 Spark 应用程序。

public class Server {

public static void main(String[] args) {
Spark.get(new VelocityRoute("/hello") {
@Override
public Object handle(final Request request, final Response response) {
Map<String, Object> model = new HashMap<String, Object>();
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");
}
});
}

public static class Person {
private String name;

public Person(String name) {
this.name = name;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
}

我的目录结构类似

src
main
java
com.stackoverflow
Server.java
resources
hello.wm

它确实选取了模板。

您使用的是哪个版本的spark-core 和spark-template-velocity?您可以检查模板文件是否已复制到 target\classes 文件夹吗?

关于java - 资源未找到异常 : for spark-java and velocity,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21341083/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com