Zio-HTTP(Zio 2.x)应用程序不从Scala 3开始
我有一个简单的应用程序:
import zhttp.http.*
import zhttp.http.Method.GET
import zhttp.service.Server
import zio.*
object HexAppApplication extends ZIOAppDefault {
// Create HTTP route
val app: HttpApp[Any, Nothing] = Http.collect[Request] {
case GET -> !! / "text" => Response.text("Hello World!")
case GET -> !! / "json" => Response.json("""{"greetings": "Hello World!"}""")
}
val program: URIO[Any, ExitCode] = Server.start(8090, app).exitCode
override def run: URIO[Any, ExitCode] = program
}
服务器立即启动和停止。为什么不停下来?
build.sbt
val zioVersion = "2.0.0-RC5"
val zioHttpVersion = "2.0.0-RC6"
libraryDependencies += "dev.zio" %% "zio" % zioVersion
libraryDependencies ++= Seq(
"dev.zio" %% "zio-test" % zioVersion % "test",
"dev.zio" %% "zio-test-sbt" % zioVersion % "test",
"dev.zio" %% "zio-test-magnolia" % zioVersion % "test" // optional
)
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
libraryDependencies += "io.d11" %% "zhttp" % zioHttpVersion
libraryDependencies += "io.d11" %% "zhttp-test" % zioHttpVersion % Test
文档中的样本(对于Scala 2.x)看起来相似:
import zio._
import zhttp.http._
import zhttp.service.Server
object HelloWorld extends App {
val app = Http.collect[Request] {
case Method.GET -> !! / "text" => Response.text("Hello World!")
}
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
Server.start(8090, app).exitCode
}
I have this simple application:
import zhttp.http.*
import zhttp.http.Method.GET
import zhttp.service.Server
import zio.*
object HexAppApplication extends ZIOAppDefault {
// Create HTTP route
val app: HttpApp[Any, Nothing] = Http.collect[Request] {
case GET -> !! / "text" => Response.text("Hello World!")
case GET -> !! / "json" => Response.json("""{"greetings": "Hello World!"}""")
}
val program: URIO[Any, ExitCode] = Server.start(8090, app).exitCode
override def run: URIO[Any, ExitCode] = program
}
The server starts and stops right away. Why doesn't it stay started?
build.sbt
val zioVersion = "2.0.0-RC5"
val zioHttpVersion = "2.0.0-RC6"
libraryDependencies += "dev.zio" %% "zio" % zioVersion
libraryDependencies ++= Seq(
"dev.zio" %% "zio-test" % zioVersion % "test",
"dev.zio" %% "zio-test-sbt" % zioVersion % "test",
"dev.zio" %% "zio-test-magnolia" % zioVersion % "test" // optional
)
testFrameworks += new TestFramework("zio.test.sbt.ZTestFramework")
libraryDependencies += "io.d11" %% "zhttp" % zioHttpVersion
libraryDependencies += "io.d11" %% "zhttp-test" % zioHttpVersion % Test
The sample from the documentation (for Scala 2.x) looks similar:
import zio._
import zhttp.http._
import zhttp.service.Server
object HelloWorld extends App {
val app = Http.collect[Request] {
case Method.GET -> !! / "text" => Response.text("Hello World!")
}
override def run(args: List[String]): URIO[zio.ZEnv, ExitCode] =
Server.start(8090, app).exitCode
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试更新
Ziohttpversion
为“ 2.0.0-rc7”。这为我修复了。Try updating
zioHttpVersion
to "2.0.0-RC7". That fixed it for me.似乎问题是
Zio-Http
是根据Zio
在版本v2.0.0.0-rc6
中构建的,因此最终尚不可用2.0.0
也不是以下的任何内容v2.0.0-rc6
[版本]( https://discordapp.com/channels/6294915970827530/8197031292672113/999550919550195015209000 )。对新最终Zio版本的支持仅合并了,因此没有人应该再次遇到此链接到GitHub prIt seems that the problem was that
zio-http
was build againstzio
in versionv2.0.0-RC6
so it is not yet usable with final2.0.0
nor anything belowv2.0.0-RC6
[version] (https://discordapp.com/channels/629491597070827530/819703129267372113/995509195015209000). The support for new final zio release has been just merged so no one should run into this again link to github PR