2017-08-15 3 views
0

私はスカラ・フィンチ・ライブラリを使用してAPIを構築しようとしています。フィンチ・ハロー・ワールド・エラー:Httpはcom.twitter.finagleのメンバーではありません

私は次の簡単なコードを持っている:

package example 

import io.finch._ 
import com.twitter.finagle.Http 

object HelloWorld extends App { 

    val api: Endpoint[String] = get("hello") { Ok("Hello, World!") } 

    Http.serve(":8080", api.toService) 
} 

そして、このようになりますbuild.sbtファイル:私はこのエラーメッセージを取得するコードをコンパイルして実行すると

name := "hello-finch" 

version := "1.0" 

scalaVersion := "2.10.6" 

mainClass in (Compile, run) := Some("example.HelloWorld") 

libraryDependencies ++= Seq(
    "com.github.finagle" %% "finch-core" % "0.10.0" 
) 

// found here: https://github.com/finagle/finch/issues/604 
addCompilerPlugin(
    "org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full 
) 

object Http is not a member of package com.twitter.finagle 
[error] import com.twitter.finagle.Http 
[error]  ^
[error] /Users/jamesk/Code/hello_finch/hello-finch/src/main/scala/example/Hello.scala:8: wrong number of type arguments for io.finch.Endpoint, should be 2 
[error] val api: Endpoint[String] = get("hello") { Ok("Hello, World!") } 
[error]   ^
[error] /Users/jamesk/Code/hello_finch/hello-finch/src/main/scala/example/Hello.scala:8: not found: value get 
[error] val api: Endpoint[String] = get("hello") { Ok("Hello, World!") } 
[error]        ^
[error] /Users/jamesk/Code/hello_finch/hello-finch/src/main/scala/example/Hello.scala:10: not found: value Http 
[error] Http.serve(":8080", api.toService) 
[error] ^
[error] four errors found 
[error] (compile:compileIncremental) Compilation failed 
[error] Total time: 1 s, completed Aug 15, 2017 12:56:01 PM 

この時点ではアイデアが不足していますが、これは良いライブラリのように見えますが、それはうまく動作しませんng。どんな助けも非常に高く評価されるでしょう。

答えて

2

私はフィンチの最後のバージョンで動作するようにあなたの例を更新しました:"com.github.finagle" %% "finch-core" % "0.15.1"ともScala 2.12

build.sbtファイル:その後、

name := "hello-finch" 

version := "1.0" 

scalaVersion := "2.12.2" 

mainClass in (Compile, run) := Some("example.HelloWorld") 

libraryDependencies ++= Seq(
    "com.github.finagle" %% "finch-core" % "0.15.1" 
) 

src/main/scala/example/HelloWorld.scalaファイル:

package example 

import io.finch._ 
import com.twitter.finagle.Http 
import com.twitter.util.Await 

object HelloWorld extends App { 
    val api: Endpoint[String] = get("hello") { Ok("Hello, World!") } 
    Await.ready(Http.server.serve(":8080", api.toServiceAs[Text.Plain])) 
} 

Await.ready()を持っていることは必須です。プログラムはすぐに終了します。

関連する問題