zio-http (ZIO 2.x) 应用程序不是从 Scala 3 开始的

zio-http (ZIO 2.x) application not starting with 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
}

尝试将 zioHttpVersion 更新为“2.0.0-RC7”。这对我来说已经解决了。