【问题标题】:Lift RestHelper don't receive my requestLift RestHelper 没有收到我的请求
【发布时间】:2015-06-30 11:14:45
【问题描述】:

我尝试创建一个简单的RestHelper“Hello world”示例,但遇到了麻烦。当我使用 container:start 命令启动容器时,

serve {
    case Nil Get _ => Extraction.decompose("Hello Restful world!")
  }

在我的RestHelper 扩展中没有被调用。我收到以下消息: “在此服务器上找不到请求的 URL /”

所以,似乎由于某种原因电梯忽略了

LiftRules.statelessDispatch.append(Service)

bootstrap.Boot.boot 定义中的行。而且我完全不知道为什么会这样。

这是我的Boot 课程:

package bootstrap

import net.liftweb.http.LiftRules
import com.yac.restfultest.Service

class Boot {
  def boot {
    LiftRules.statelessDispatch.append(Service)
  }
}

这里是Service

package com.yac.restfultest

import net.liftweb.http.rest.RestHelper
import net.liftweb.json.Extraction

object Service extends RestHelper {

  serve {
    case Nil Get _ => Extraction.decompose("Hello Restful world!")
  }

}

如果有帮助,这里是我的web.xml

<!DOCTYPE web-app SYSTEM "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
    <filter>
        <filter-name>LiftFilter</filter-name>
        <display-name>Lift Filter</display-name>
        <description>The Filter that intercepts Lift calls</description>
        <filter-class>net.liftweb.http.LiftFilter</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>LiftFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
</web-app>

如果以上所有内容还不够,这里是我的build.sbt

name := "TestRest"

version := "1.0"

scalaVersion := "2.11.6"

resolvers ++= Seq("snapshots" at "https://oss.sonatype.org/content/repositories/snapshots",
  "releases" at "https://oss.sonatype.org/content/repositories/releases"
)

jetty()

libraryDependencies ++= {

  val liftVersion = "2.6.2"

  Seq(
    "net.liftweb" %% "lift-webkit" % liftVersion % "compile"
  )

}

如您所见,这几乎是最简约的电梯项目设置。我仍然无法让它工作。任何帮助将不胜感激。

这里是sbt 登录container:start

[info] Compiling 1 Scala source to /home/yac/IdeaProjects/TestRest/target/scala-2.11/classes...
[info] Packaging /home/yac/IdeaProjects/TestRest/target/scala-2.11/testrest_2.11-1.0.jar ...
[info] Done packaging.
[info] starting server ...
[success] Total time: 2 s, completed Apr 22, 2015 7:51:25 PM
> 2015-04-22 19:51:25.640:INFO::main: Logging initialized @44ms
2015-04-22 19:51:25.646:INFO:oejr.Runner:main: Runner
2015-04-22 19:51:25.726:INFO:oejs.Server:main: jetty-9.2.1.v20140609
2015-04-22 19:51:29.818:WARN:oeja.AnnotationConfiguration:main: ServletContainerInitializers: detected. Class hierarchy: empty
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
2015-04-22 19:51:30.405:INFO:oejsh.ContextHandler:main: Started o.e.j.w.WebAppContext@32e377c7{/,file:/home/yac/IdeaProjects/TestRest/target/webapp/,AVAILABLE}{file:/home/yac/IdeaProjects/TestRest/target/webapp/}
2015-04-22 19:51:30.406:WARN:oejsh.RequestLogHandler:main: !RequestLog
2015-04-22 19:51:30.417:INFO:oejs.ServerConnector:main: Started ServerConnector@7a601e4{HTTP/1.1}{0.0.0.0:8080}
2015-04-22 19:51:30.418:INFO:oejs.Server:main: Started @4848ms

【问题讨论】:

  • 您是否尝试过匹配:"index" :: Nil 而不是简单的Nil
  • 我什至尝试将路由设置为“test” :: “item” :: Nil。还是没用。

标签: scala sbt lift


【解决方案1】:

所以,事实证明这是一种平常的粗心大意。包含Boot.scala 的包应该称为bootstrap.liftweb 而不仅仅是bootstrap,就像我的例子一样。

是的,正如 jcern 所建议的,在路由模式中应该是 "index" :: Nil

【讨论】:

    猜你喜欢
    • 2019-01-07
    • 1970-01-01
    • 2012-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多