播放:迁移2.5到2.6:错误ProvisionException

时间:2017-10-23 12:41:02

标签: scala dependency-injection playframework-2.6

从Play版本2.5迁移到2.6时出现错误。

以下是我已应用的操作列表:

  • sbt clean

  • sbt compile

  • sbt update

  • sbt eclipse

    我得到了这个例外

    ProvisionException:无法配置,请参阅以下错误:

    1)注入构造函数时出错,java.lang.NoClassDefFoundError:org / pac4j / play / scala / Security $ class   在controllers.EntityController。(EntityController.scala:50)   在controllers.EntityController.class(EntityController.scala:50)   同时找到controllers.EntityController     对于router.Routes。的第4个参数。(Routes.scala:50)   同时找到router.Routes   找到play.api.inject.RoutesProvider   找到play.api.routing.Router     对于play.api.http.JavaCompatibleHttpRequestHandler的第一个参数。(HttpRequestHandler.scala:222)   找到play.api.http.JavaCompatibleHttpRequestHandler   找到play.api.http.HttpRequestHandler     对于play.api.DefaultApplication的第6个参数。(Application.scala:236)   at play.api.DefaultApplication.class(Application.scala:235)   找到play.api.DefaultApplication   找到play.api.Application 引起:java.lang.NoClassDefFoundError:org / pac4j / play / scala / Security $ class     在controllers.EntityController。(EntityController.scala:60)     在controllers.EntityController $$ FastClassByGuice $$ f46ad4b6.newInstance()     在com.google.inject.internal.DefaultConstructionProxyFactory $ FastClassProxy.newInstance(DefaultConstructionProxyFactory.java:89)     在com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:111)     在com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)     在com.google.inject.internal.ConstructorBindingImpl $ Factory.get(ConstructorBindingImpl.java:268)     在com.google.inject.internal.ProviderToInternalFactoryAdapter $ 1.call(ProviderToInternalFactoryAdapter.java:46)     在com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)     在com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)     在com.google.inject.internal.SingletonScope $ 1.get(SingletonScope.java:194)     在com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)     在com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)     在com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)     在com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:110)     在com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)     在com.google.inject.internal.ConstructorBindingImpl $ Factory.get(ConstructorBindingImpl.java:268)     在com.google.inject.internal.InjectorImpl $ 2 $ 1.call(InjectorImpl.java:1019)     在com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)     在com.google.inject.internal.InjectorImpl $ 2.get(InjectorImpl.java:1015)     在com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1054)     at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:409)     at play.api.inject.ContextClassLoaderInjector $$ anonfun $ instanceOf $ 3.apply(Injector.scala:118)     at play.api.inject.ContextClassLoaderInjector.withContext(Injector.scala:126)     at play.api.inject.ContextClassLoaderInjector.instanceOf(Injector.scala:118)     at play.api.inject.RoutesProvider $$ anonfun $ 2.apply(BuiltinModule.scala:104)     at play.api.inject.RoutesProvider $$ anonfun $ 2.apply(BuiltinModule.scala:104)     在scala.Option.fold(Option.scala:158)     at play.api.inject.RoutesProvider.get $ lzycompute(BuiltinModule.scala:104)     at play.api.inject.RoutesProvider.get(BuiltinModule.scala:100)     at play.api.inject.RoutesProvider.get(BuiltinModule.scala:99)     在com.google.inject.internal.ProviderInternalFactory.provision(ProviderInternalFactory.java:81)     在com.google.inject.internal.BoundProviderFactory.provision(BoundProviderFactory.java:72)     在com.google.inject.internal.ProviderInternalFactory.circularGet(ProviderInternalFactory.java:61)     在com.google.inject.internal.BoundProviderFactory.get(BoundProviderFactory.java:62)     在com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)     在com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)     在com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:110)     在com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)     在com.google.inject.internal.ConstructorBindingImpl $ Factory.get(ConstructorBindingImpl.java:268)     在com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:56)     在com.google.inject.internal.SingleParameterInjector.inject(SingleParameterInjector.java:38)     在com.google.inject.internal.SingleParameterInjector.getAll(SingleParameterInjector.java:62)     在com.google.inject.internal.ConstructorInjector.provision(ConstructorInjector.java:110)     在com.google.inject.internal.ConstructorInjector.construct(ConstructorInjector.java:90)     在com.google.inject.internal.ConstructorBindingImpl $ Factory.get(ConstructorBindingImpl.java:268)     在com.google.inject.internal.ProviderToInternalFactoryAdapter $ 1.call(ProviderToInternalFactoryAdapter.java:46)     在com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1092)     在com.google.inject.internal.ProviderToInternalFactoryAdapter.get(ProviderToInternalFactoryAdapter.java:40)     在com.google.inject.internal.SingletonScope $ 1.get(SingletonScope.java:194)     在com.google.inject.internal.InternalFactoryToProviderAdapter.get(InternalFactoryToProviderAdapter.java:41)     在com.google.inject.internal.FactoryProxy.get(FactoryProxy.java:56)     在com.google.inject.internal.InjectorImpl $ 2 $ 1.call(InjectorImpl.java:1019)     在com.google.inject.internal.InjectorImpl.callInContext(InjectorImpl.java:1085)     在com.google.inject.internal.InjectorImpl $ 2.get(InjectorImpl.java:1015)     在com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1054)     at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:409)     at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:404)     at play.api.inject.ContextClassLoaderInjector $$ anonfun $ instanceOf $ 2.apply(Injector.scala:117)     at play.api.inject.ContextClassLoaderInjector.withContext(Injector.scala:126)     at play.api.inject.ContextClassLoaderInjector.instanceOf(Injector.scala:117)     at play.api.inject.guice.GuiceApplicationBuilder.build(GuiceApplicationBuilder.scala:137)     at play.api.inject.guice.GuiceApplicationLoader.load(GuiceApplicationLoader.scala:21)     at play.core.server.DevServerStart $$ anonfun $ mainDev $ 1 $$ anon $ 1 $$ anonfun $ 1.apply(DevServerStart.scala:174)     at play.core.server.DevServerStart $$ anonfun $ mainDev $ 1 $$ anon $ 1 $$ anonfun $ 1.apply(DevServerStart.scala:171)     at play.utils.Threads $ .withContextClassLoader(Threads.scala:21)     at play.core.server.DevServerStart $$ anonfun $ mainDev $ 1 $$ anon $ 1.reload(DevServerStart.scala:171)     at play.core.server.DevServerStart $$ anonfun $ mainDev $ 1 $$ anon $ 1.get(DevServerStart.scala:124)     at play.core.server.AkkaHttpServer.play $ core $ server $ AkkaHttpServer $$ modelConversion(AkkaHttpServer.scala:183)     at play.core.server.AkkaHttpServer.play $ core $ server $ AkkaHttpServer $$ handleRequest(AkkaHttpServer.scala:189)     at play.core.server.AkkaHttpServer $$ anonfun $ 5.apply(AkkaHttpServer.scala:106)     at play.core.server.AkkaHttpServer $$ anonfun $ 5.apply(AkkaHttpServer.scala:106)     at akka.stream.impl.fusing.MapAsync $$ anon $ 23.onPush(Ops.scala:1172)     at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:499)     at akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:462)     at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:368)     at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:571)     at akka.stream.impl.fusing.GraphInterpreterShell $ AsyncInput.execute(ActorGraphInterpreter.scala:457)     at akka.stream.impl.fusing.GraphInterpreterShell.processEvent(ActorGraphInterpreter.scala:546)     at akka.stream.impl.fusing.ActorGraphInterpreter.akka $ stream $ impl $ fusing $ ActorGraphInterpreter $$ processEvent(ActorGraphInterpreter.scala:725)     at akka.stream.impl.fusing.ActorGraphInterpreter $$ anonfun $ receive $ 1.applyOrElse(ActorGraphInterpreter.scala:740)     at akka.actor.Actor $ class.aroundReceive(Actor.scala:514)     at akka.stream.impl.fusing.ActorGraphInterpreter.aroundReceive(ActorGraphInterpreter.scala:650)     at akka.actor.ActorCell.receiveMessage(ActorCell.scala:527)     at akka.actor.ActorCell.invoke(ActorCell.scala:496)     at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:257)     at akka.dispatch.Mailbox.run(Mailbox.scala:224)     at akka.dispatch.Mailbox.exec(Mailbox.scala:234)     at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)     at akka.dispatch.forkjoin.ForkJoinPool $ WorkQueue.runTask(ForkJoinPool.java:1339)     at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)     at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) 引起:java.lang.ClassNotFoundException:org.pac4j.play.scala.Security $ class     at java.net.URLClassLoader.findClass(URLClassLoader.java:381)     at java.lang.ClassLoader.loadClass(ClassLoader.java:424)     at java.lang.ClassLoader.loadClass(ClassLoader.java:357)     ... 91更多

使用安全性的类是这个

@Singleton
class EntityController @Inject() (val controllerComponents: ControllerComponents,
                                  val config: Config,
                                  val entities: EntityRepository,
                                  val configextractor: ConfigExtractor,
                                  val calendars: CalendarRepository,
                                  val kpis: KpiExtractor,
                                  val authz: EntityAuthorizer,
                                  val playSessionStore: PlaySessionStore,
                                  val searchService: SearchService,
                                  implicit val ec: ComputeExecutionContext
                                 ) extends BaseController with Security[CommonProfile] with KpiAware{

我写了文件sbt。

name := """fons"""
organization := "com.luxottica.retail"

version := "1.0-SNAPSHOT"

lazy val root = (project in file(".")).enablePlugins(PlayScala)

scalaVersion := "2.11.8"

// Dependencies
libraryDependencies ++= Seq(
  ws,
  filters,
  cacheApi,
  openId,
  guice,
  "commons-io" % "commons-io" % "2.5",
  "com.github.romix.akka" %% "akka-kryo-serialization" % "0.5.0",
  "com.github.simonedeponti" %% "play26-lettuce" % "0.1",
  "joda-time" % "joda-time" % "2.9.9",
  "org.mongodb.scala" %% "mongo-scala-driver" % "2.1.0",
  "org.pac4j" % "play-pac4j" % "4.0.0",
  "org.pac4j" % "pac4j-core" % "2.1.0",
  "org.pac4j" % "pac4j-http" % "2.1.0",
  "org.pac4j" % "pac4j-jwt" % "2.1.0" exclude("commons-io" , "commons-io"),
  "org.pac4j" % "pac4j-ldap" % "2.1.0",  
  "com.microsoft.azure" % "applicationinsights-core" % "1.0.10",
  "com.microsoft.azure" % "applicationinsights-logging-logback" % "1.0.10",
  "com.github.t3hnar" %% "scala-bcrypt" % "3.0",
  "org.scalariform" %% "scalariform" % "0.2.3"
)

// Test dependencies
libraryDependencies ++= Seq(
  "org.scalatestplus.play" %% "scalatestplus-play" % "2.0.0" % Test,
  "org.mockito" % "mockito-all" % "1.10.19" % Test,
  "junit" % "junit" % "4.12" % Test,
  "org.scalaz" %% "scalaz-core" % "7.1.1" % Test
)


resolvers ++= Seq(
  "snapshots" at "http://oss.sonatype.org/content/repositories/snapshots",
  "releases"  at "http://oss.sonatype.org/content/repositories/releases",
  "Scalaz Bintray Repo" at "http://dl.bintray.com/scalaz/releases",
  "Simone's repos" at "https://dl.bintray.com/simonedeponti/maven"
)

routesGenerator := InjectedRoutesGenerator

scalacOptions += "-deprecation"

evictionWarningOptions in update := EvictionWarningOptions.default.withWarnTransitiveEvictions(false)


// Adds additional packages into Twirl
//TwirlKeys.templateImports += "com.luxottica.retail.controllers._"

// Adds additional packages into conf/routes
// play.sbt.routes.RoutesKeys.routesImport += "com.luxottica.retail.binders._"

assemblyMergeStrategy in assembly := {
  case m if m.toLowerCase.endsWith("manifest.mf")          => MergeStrategy.discard
  case m if m.toLowerCase.matches("meta-inf.*\\.sf$")      => MergeStrategy.discard
  case "log4j.properties"                                  => MergeStrategy.discard
  case m if m.toLowerCase.startsWith("meta-inf/services/") => MergeStrategy.filterDistinctLines
  case "reference.conf"                                    => MergeStrategy.concat
  case _                                                   => MergeStrategy.first
}

有什么需要改变?

1 个答案:

答案 0 :(得分:0)

我们遇到了同样的问题,我们修复了将Scala升级到2.12

的问题

https://github.com/pac4j/play-pac4j/issues/207