Lift RestHelper不接收我的请求

时间:2015-04-22 16:27:48

标签: scala sbt lift

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

serve {
    case Nil Get _ => Extraction.decompose("Hello Restful world!")
  }
我的RestHelper扩展程序中未调用

。我收到以下消息: “在此服务器上找不到请求的网址”

所以,似乎由于某种原因,提升忽略了

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

1 个答案:

答案 0 :(得分:0)

所以,事实证明这是一种常见的非注意力。包含assign leadingBits = magnitude[bitsEnd+3 -: 4]; 的包应该被称为Boot.scala,而不仅仅是bootstrap.liftweb

是的,正如 jcern 所建议的那样,在路由模式中它应该是bootstrap