Scala 一个文件中的路由路径前缀

Scala 一个文件中的路由路径前缀,scala,akka,akka-http,Scala,Akka,Akka Http,我正在尝试将所有路由移动到一个文件中,以便在将来添加路由时,不需要创建新的控制器类 我的代码现在是这样的: 在控制器.scala中: trait controller { def route(path: PathMatcher[Unit], port: Int) = pathPrefix(path) { ... } } 在HttpRoutes.scala中 route("health", 3000) ~ route("", 4000) 第二部分包含所有其他路线 这似乎不起作用

我正在尝试将所有路由移动到一个文件中,以便在将来添加路由时,不需要创建新的
控制器

我的代码现在是这样的:

控制器.scala中

trait controller {
  def route(path: PathMatcher[Unit], port: Int) = pathPrefix(path) {
    ...
  }
}
HttpRoutes.scala中

route("health", 3000) ~ route("", 4000)
第二部分包含所有其他路线

这似乎不起作用,因为在我的单元测试中:

GET("/testing") ~> c.route("/testing", 4000) ~> check {
  handled shouldBe true
}

handled返回false。

我发现了这个问题,因为函数
route
需要一个
pathMatcher
,在mu单元测试中,我应该使用
c.route(“”,4000)
而不是
c.route(“/testing”,4000)
来捕获所有流量。