gpt4 book ai didi

playframework-2.0 - Play Framework Swagger UI 集成错误

转载 作者:行者123 更新时间:2023-12-01 22:09:40 30 4
gpt4 key购买 nike

我正在尝试为 Play Framework 2.5.x 提供的 Rest API 集成 Swagger UI

我做了以下事情:

  1. 在我的 build.sbt 中包含以下依赖项
  "io.swagger" %% "swagger-play2" % "1.5.3"
"org.webjars" %% "webjars-play" % "2.5.0-4"
"org.webjars" % "swagger-ui" % "2.2.0"
  1. 将以下内容添加到我的 route :
GET         /swagger.json                controllers.ApiHelpController.getResources
GET /docs/ controllers.Assets.at(path="/public/swagger-ui",file="index.html")
GET /docs/*file controllers.Assets.at(path="/public/swagger-ui",file)
  1. 然后我尝试访问 swagger.json

这是我得到的错误:

[error] application -

! @77515gnlp - Internal server error, for (GET) [/swagger.json] ->

play.api.http.HttpErrorHandlerExceptions$$anon$1: Execution exception[[NullPointerException: null]]
at play.api.http.HttpErrorHandlerExceptions$.throwableToUsefulException(HttpErrorHandler.scala:280)
at play.api.http.DefaultHttpErrorHandler.onServerError(HttpErrorHandler.scala:206)
at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:100)
at play.core.server.netty.PlayRequestHandler$$anonfun$2$$anonfun$apply$1.applyOrElse(PlayRequestHandler.scala:99)
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:346)
at scala.concurrent.Future$$anonfun$recoverWith$1.apply(Future.scala:345)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:36)
at play.api.libs.iteratee.Execution$trampoline$.execute(Execution.scala:70)
at scala.concurrent.impl.CallbackRunnable.executeWithValue(Promise.scala:44)
at scala.concurrent.impl.Promise$DefaultPromise.tryComplete(Promise.scala:252)
Caused by: java.lang.NullPointerException: null
at play.modules.swagger.ApiListingCache$$anonfun$listing$1.apply(ApiListingCache.scala:15)
at play.modules.swagger.ApiListingCache$$anonfun$listing$1.apply(ApiListingCache.scala:11)
at scala.Option.orElse(Option.scala:289)
at play.modules.swagger.ApiListingCache$.listing(ApiListingCache.scala:11)
at controllers.SwaggerBaseApiController.getResourceListing(ApiHelpController.scala:128)
at controllers.ApiHelpController$$anonfun$getResources$1.apply(ApiHelpController.scala:74)
at controllers.ApiHelpController$$anonfun$getResources$1.apply(ApiHelpController.scala:71)
at play.api.mvc.ActionBuilder$$anonfun$apply$13.apply(Action.scala:371)
at play.api.mvc.ActionBuilder$$anonfun$apply$13.apply(Action.scala:370)
at play.api.mvc.Action$.invokeBlock(Action.scala:498)

还有什么我应该添加或研究的吗?

最佳答案

您似乎没有在您的application.conf 中启用 swagger 模块:

play.modules.enabled += "play.modules.swagger.SwaggerModule"

我建议您引用这篇很棒的博文,了解与 play 框架的正确 swagger 集成:Medium article

祝你好运:)

关于playframework-2.0 - Play Framework Swagger UI 集成错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48974996/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com