0

我有火花的问题。我正在尝试加载视图“base.hbs”,但每当我尝试加载它时,火花都会引发 FileNotFoundException

我尝试将构造函数更改为 new HandlebarsTemplateEngine("tried/different/paths/here"); 但没有运气。我什至尝试将资源文件夹放在 C:/ Drive 并从外部加载它,但仍然没有运气......

我没有使用常规的嵌入式 Jetty 服务器,但我使用的是 tomcat 服务器...我可以向您保证其他 get 方法有效(我返回字符串的地方)

非常感谢您的帮助。

代码:

@Override
public void init() {

    Map map = new HashMap();
    map.put("name", "Sam Cooke");

    get("/hello", (rq, rs) -> {
        System.out.println(rq.contextPath());

        return new ModelAndView(map, "base.hbs");}, new HandlebarsTemplateEngine("resources/templates/"));

    exception(Exception.class, (ex, rq, rs)->{ex.printStackTrace();});
}

文件夹结构:

文件结构

例外:

org.eclipse.jetty.io.RuntimeIOException: java.io.FileNotFoundException: resources/templates/base.hbs
at spark.template.handlebars.HandlebarsTemplateEngine.render(HandlebarsTemplateEngine.java:78)
at spark.TemplateViewRouteImpl$1.render(TemplateViewRouteImpl.java:61)
at spark.TemplateViewRouteImpl$1.render(TemplateViewRouteImpl.java:58)
at spark.TemplateViewRouteImpl.render(TemplateViewRouteImpl.java:85)
at spark.http.matching.Routes.execute(Routes.java:62)
at spark.http.matching.MatcherFilter.doFilter(MatcherFilter.java:126)
at spark.servlet.SparkFilter.doFilter(SparkFilter.java:119)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:521)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1096)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:674)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1456)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)


Caused by: java.io.FileNotFoundException: resources/templates/base.hbs
at com.github.jknack.handlebars.io.URLTemplateLoader.sourceAt(URLTemplateLoader.java:70)
at com.github.jknack.handlebars.Handlebars.compile(Handlebars.java:391)
at com.github.jknack.handlebars.Handlebars.compile(Handlebars.java:377)
at spark.template.handlebars.HandlebarsTemplateEngine.render(HandlebarsTemplateEngine.java:75)
... 24 more
4

1 回答 1

0

事实证明,答案是重新启动 Eclipse... 天哪,这是通过重新启动解决的错误的一天...谢谢剪辑...

于 2016-06-29T08:22:12.137 回答