【发布时间】:2018-10-06 18:45:47
【问题描述】:
我第一次在 Java 中尝试 AKKA-Http(akka-http_2.12 v 10.1.5,akka-stream_2.12 v 2.5.17),但似乎无法为招摇加载静态内容用户界面。我已经添加了下面的路由,并且能够通过 http://localhost:8080/api-docs/swagger.json 和 http://localhost:8080/api-docs/swagger.yaml 到达 json 和 yaml swagger 端点但是,swagger UI 端点,即 http://localhost:8080/swagger 返回 'There was an internal server error.' 即使我在 src/main/resources 文件夹下有 swagger-ui 目录。我检查了日志,但不太明白发生了什么......似乎是 getFromResource 和 getFromResourceDirectory 函数中的错误。 Similar issue was reported earlier
Route createRoute() {
return route(
path(PathMatchers.segment(generator.apiDocsPath()).slash("swagger.yaml"),
() -> get(() -> complete(generator.generateSwaggerYaml()))),
path(PathMatchers.segment(generator.apiDocsPath()).slash("swagger.json"),
() -> get(() -> complete(generator.generateSwaggerJson()))),
path("swagger", () -> route (
getFromResource("swagger-ui/index.html"),
getFromResourceDirectory("swagger-ui")
)
)
);
}
akka-spring-docker-system | 2018-10-06 08:27:11.292 ERROR 9 --- [lt-dispatcher-8] akka.actor.ActorSystemImpl : Error during processing of request: 'java.lang.NullPointerException (No error message supplied)'. Completing with 500 Internal Server Error response. To change default exception handling behavior, provide a custom ExceptionHandler.
akka-spring-docker-system |
akka-spring-docker-system | java.lang.NullPointerException: null
akka-spring-docker-system | at akka.http.scaladsl.server.directives.FileAndResourceDirectives$ResourceFile$.apply(FileAndResourceDirectives.scala:286) ~[akka-http_2.12-10.1.5.jar!/:10.1.5]
akka-spring-docker-system | at akka.http.scaladsl.server.directives.FileAndResourceDirectives.$anonfun$getFromResource$2(FileAndResourceDirectives.scala:106) ~[akka-http_2.12-10.1.5.jar!/:10.1.5]
akka-spring-docker-system | at scala.Option.flatMap(Option.scala:171) ~[scala-library-2.12.4.jar!/:na]
akka-spring-docker-system | at akka.http.scaladsl.server.directives.FileAndResourceDirectives.$anonfun$getFromResource$1(FileAndResourceDirectives.scala:106) ~[akka-http_2.12-10.1.5.jar!/:10.1.5]
【问题讨论】:
标签: java akka swagger akka-stream akka-http