Я использую play-framework 2.7 и следую этому уроку
https://github.com/swagger-api/swagger-play/tree/master/play-2.6/swagger-play2
я выполнил все шаги
добавлено
play.modules.enabled += "play.modules.swagger.SwaggerModule"
в application.conf
вот мой файл build.sbt
scalaVersion := "2.12.8"
routesGenerator := InjectedRoutesGenerator
libraryDependencies += guice
libraryDependencies += "org.scalatestplus.play" %% "scalatestplus-play" % "4.0.1" % Test
libraryDependencies += "com.h2database" % "h2" % "1.4.197"
libraryDependencies += "io.swagger" %% "swagger-play2" % "1.6.0"
libraryDependencies += "io.swagger" %% "swagger-scala-module" % "1.0.4"
вот действие контроллера
@Api
@Singleton
class CountController @Inject() (cc: ControllerComponents,
counter: Counter) extends AbstractController(cc) {
@ApiResponses(Array(
new ApiResponse(code = 400, message = "Invalid name supplied"),
new ApiResponse(code = 404, message = "Name not found")))
def sayHello(@ApiParam(value = "Name to say hello") name: String) = Action {
Ok(s"hello $name")
}
}
и вот файл маршрута
GET /hello/:name controllers.CountController.sayHello(name:String)
GET /swagger.json controllers.ApiHelpController.getResources
попадание в localhost: 9000 / привет / abc
выдает следующее исключение
play.api.UnexpectedException: Unexpected exception[CreationException: Unable to create injector, see the following errors:
1) Error injecting constructor, java.util.ServiceConfigurationError: io.swagger.converter.ModelConverter: Provider io.swagger.scala.converter.SwaggerScalaModelConverter could not be instantiated
at play.modules.swagger.SwaggerPluginImpl.<init>(SwaggerPlugin.scala:35)
while locating play.modules.swagger.SwaggerPluginImpl
at play.modules.swagger.SwaggerModule.bindings(SwaggerModule.scala:11):
Binding(interface play.modules.swagger.SwaggerPlugin to ConstructionTarget(class play.modules.swagger.SwaggerPluginImpl) eagerly) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$4)
while locating play.modules.swagger.SwaggerPlugin
1 error]
at play.core.server.DevServerStart$$anon$1.reload(DevServerStart.scala:196)
at play.core.server.DevServerStart$$anon$1.get(DevServerStart.scala:127)
at play.core.server.AkkaHttpServer.handleRequest(AkkaHttpServer.scala:253)
at play.core.server.AkkaHttpServer.$anonfun$createServerBinding$1(AkkaHttpServer.scala:149)
at akka.stream.impl.fusing.MapAsync$$anon$30.onPush(Ops.scala:1207)
at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:519)
at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:411)
at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:588)
at akka.stream.impl.fusing.GraphInterpreterShell$AsyncInput.execute(ActorGraphInterpreter.scala:472)
at akka.stream.impl.fusing.GraphInterpreterShell.processEvent(ActorGraphInterpreter.scala:563)
Caused by: com.google.inject.CreationException: Unable to create injector, see the following errors:
1) Error injecting constructor, java.util.ServiceConfigurationError: io.swagger.converter.ModelConverter: Provider io.swagger.scala.converter.SwaggerScalaModelConverter could not be instantiated
at play.modules.swagger.SwaggerPluginImpl.<init>(SwaggerPlugin.scala:35)
while locating play.modules.swagger.SwaggerPluginImpl
at play.modules.swagger.SwaggerModule.bindings(SwaggerModule.scala:11):
Binding(interface play.modules.swagger.SwaggerPlugin to ConstructionTarget(class play.modules.swagger.SwaggerPluginImpl) eagerly) (via modules: com.google.inject.util.Modules$OverrideModule -> play.api.inject.guice.GuiceableModuleConversions$$anon$4)
while locating play.modules.swagger.SwaggerPlugin
1 error
at com.google.inject.internal.Errors.throwCreationExceptionIfErrorsExist(Errors.java:543)
at com.google.inject.internal.InternalInjectorCreator.injectDynamically(InternalInjectorCreator.java:186)
at com.google.inject.internal.InternalInjectorCreator.build(InternalInjectorCreator.java:109)
at com.google.inject.Guice.createInjector(Guice.java:87)
at com.google.inject.Guice.createInjector(Guice.java:78)
at play.api.inject.guice.GuiceBuilder.injector(GuiceInjectorBuilder.scala:186)
at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:139)
at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)
at play.core.server.DevServerStart$$anon$1.$anonfun$reload$3(DevServerStart.scala:176)
at play.utils.Threads$.withContextClassLoader(Threads.scala:22)
Caused by: java.util.ServiceConfigurationError: io.swagger.converter.ModelConverter: Provider io.swagger.scala.converter.SwaggerScalaModelConverter could not be instantiated
at java.base/java.util.ServiceLoader.fail(ServiceLoader.java:581)
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:803)
at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:721)
at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1394)
at io.swagger.converter.ModelConverters.<clinit>(ModelConverters.java:114)
at play.modules.swagger.PlayReader.parseMethod(PlayReader.java:487)
at play.modules.swagger.PlayReader.read(PlayReader.java:139)
at play.modules.swagger.PlayReader.read(PlayReader.java:63)
at play.modules.swagger.PlayReader.read(PlayReader.java:57)
at play.modules.swagger.ApiListingCache$.$anonfun$listing$1(ApiListingCache.scala:17)
Caused by: java.lang.ExceptionInInitializerError: null
at io.swagger.scala.converter.SwaggerScalaModelConverter.<init>(SwaggerScalaModelConverter.scala:19)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:490)
at java.base/java.util.ServiceLoader$ProviderImpl$2.run(ServiceLoader.java:787)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at java.base/java.util.ServiceLoader$ProviderImpl.newInstance(ServiceLoader.java:792)
at java.base/java.util.ServiceLoader$ProviderImpl.get(ServiceLoader.java:721)
at java.base/java.util.ServiceLoader$3.next(ServiceLoader.java:1394)
Caused by: com.fasterxml.jackson.databind.JsonMappingException: Scala module 2.8.6 requires Jackson Databind version >= 2.8.0 and < 2.9.0
at com.fasterxml.jackson.module.scala.JacksonModule.setupModule(JacksonModule.scala:66)
at com.fasterxml.jackson.module.scala.JacksonModule.setupModule$(JacksonModule.scala:51)
at com.fasterxml.jackson.module.scala.DefaultScalaModule.setupModule(DefaultScalaModule.scala:18)
at com.fasterxml.jackson.databind.ObjectMapper.registerModule(ObjectMapper.java:751)
at io.swagger.scala.converter.SwaggerScalaModelConverter$.<init>(SwaggerScalaModelConverter.scala:15)
at io.swagger.scala.converter.SwaggerScalaModelConverter$.<clinit>(SwaggerScalaModelConverter.scala)
at io.swagger.scala.converter.SwaggerScalaModelConverter.<init>(SwaggerScalaModelConverter.scala:19)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
Я исследовал это и добавил "io.swagger" %% "swagger-scala-module" % "1.0.4"
, но проблема сохраняется