我正在尝试在运行时使用特征聚合路由,到目前为止我有
object SMController {
def aggregateRoutes(actorSystem: ActorSystem): List[Route] = {
val runtimeMirror = universe.runtimeMirror(getClass.getClassLoader)
val reflections = new Reflections("com.example.api")
val subclasses = reflections.getSubTypesOf(classOf[Routable])
val routesList = new ListBuffer[Route]()
for (i <- subclasses) {
val module = runtimeMirror.staticModule(i.getName)
val obj = runtimeMirror.reflectModule(module)
val someTrait: Routable = obj.instance.asInstanceOf[Routable]
routesList += someTrait.getAllRoutes(actorSystem)
}
routesList.toList
}
}
显然上面的代码不起作用,因为项目列表不能传递给Http().bindAndHandle
.
所以我的问题是,如何将 解析List[Routes]
为Http().bindAndHandle
接受,或者如何从 的子类动态加载路由Routable
?