【问题标题】:Scalate ResourceNotFoundException in Scalatra在 Scalatra 中缩放 ResourceNotFoundException
【发布时间】:2011-07-19 06:42:14
【问题描述】:

我正在基于 scalatra-sbt.g8 尝试以下操作:

class FooWeb extends ScalatraServlet with ScalateSupport {
  beforeAll { contentType = "text/html" }
  get("/") {
    templateEngine.layout("/WEB-INF/scalate/templates/hello-scalate.jade")
  }
}

但我得到以下异常(即使文件存在) - 任何线索?

Could not load resource: [/WEB-INF/scalate/templates/hello-scalate.jade]; are you sure it's within [null]?

org.fusesource.scalate.util.ResourceNotFoundException: Could not load resource: [/WEB-INF/scalate/templates/hello-scalate.jade]; are you sure it's within [null]?

FWIW,最里面的异常来自 org.mortbay.jetty.handler.ContextHandler.getResource 第 1142 行:_baseResource==null

【问题讨论】:

    标签: scala scalate scalatra


    【解决方案1】:

    从 scalatra 邮件列表中获得了答案。问题是我正在启动 Jetty 服务器:

    import org.mortbay.jetty.Server
    import org.mortbay.jetty.servlet.{Context,ServletHolder}
    val server = new Server(8080)
    val root = new Context(server, "/", Context.SESSIONS)
    root.addServlet(new ServletHolder(new FooWeb()), "/*")
    server.start()
    

    我需要在start()之前插入这个:

    root.setResourceBase("src/main/webapp")
    

    【讨论】: