获取Guice升级Play 2.4.3后,无法在play.core.ObjectMapperPlugin中找到合适的构造函数

时间:2015-12-26 04:37:15

标签: scala playframework scalatest

在将Play框架升级到2.4.3后尝试为我的播放应用程序运行ScalaTest测试时出现以下异常

在嵌套套件上调用run时遇到异常 - Guice配置错误:

1)在play.core.ObjectMapperPlugin中找不到合适的构造函数。

Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
  at play.core.ObjectMapperPlugin.class(ObjectMapperPlugin.scala:17)
  while locating play.core.ObjectMapperPlugin

1 error
com.google.inject.ConfigurationException: Guice configuration errors:

1) Could not find a suitable constructor in play.core.ObjectMapperPlugin. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
  at play.core.ObjectMapperPlugin.class(ObjectMapperPlugin.scala:17)
  while locating play.core.ObjectMapperPlugin

1 error
    at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1042)
    at com.google.inject.internal.InjectorImpl.getProvider(InjectorImpl.java:1001)
    at com.google.inject.internal.InjectorImpl.getInstance(InjectorImpl.java:1051)
    at play.api.inject.guice.GuiceInjector.instanceOf(GuiceInjectorBuilder.scala:321)
    at play.api.Plugins$$anonfun$loadPlugins$1.apply(Plugins.scala:89)
    at play.api.Plugins$$anonfun$loadPlugins$1.apply(Plugins.scala:87)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:245)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at scala.collection.TraversableLike$class.map(TraversableLike.scala:245)
    at scala.collection.immutable.List.map(List.scala:285)
    at play.api.Plugins$.loadPlugins(Plugins.scala:87)
    at play.api.test.FakePluginsProvider$$anonfun$get$1.apply(Fakes.scala:234)
    at play.api.test.FakePluginsProvider$$anonfun$get$1.apply(Fakes.scala:234)
    at play.api.Plugins.thePlugins$lzycompute(Plugins.scala:59)
    at play.api.Plugins.thePlugins(Plugins.scala:59)
    at play.api.Plugins.length(Plugins.scala:60)
    at scala.collection.IndexedSeqLike$class.iterator(IndexedSeqLike.scala:90)
    at play.api.Plugins.iterator(Plugins.scala:57)
    at scala.collection.IterableLike$class.foreach(IterableLike.scala:72)
    at play.api.Plugins.foreach(Plugins.scala:57)
    at play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:92)
    at play.api.Play$$anonfun$start$1.apply(Play.scala:87)
    at play.api.Play$$anonfun$start$1.apply(Play.scala:87)
    at play.utils.Threads$.withContextClassLoader(Threads.scala:21)
    at play.api.Play$.start(Play.scala:87)
    at org.scalatestplus.play.OneAppPerSuite$class.run(OneAppPerSuite.scala:139)
    at controllers.SchoolAdminContactSpec.run(SchoolAdminContactSpec.scala:14)
    at org.scalatest.tools.SuiteRunner.run(SuiteRunner.scala:55)
    at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$3.apply(Runner.scala:2563)
    at org.scalatest.tools.Runner$$anonfun$doRunRunRunDaDoRunRun$3.apply(Runner.scala:2557)
    at scala.collection.immutable.List.foreach(List.scala:381)
    at org.scalatest.tools.Runner$.doRunRunRunDaDoRunRun(Runner.scala:2557)
    at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1044)
    at org.scalatest.tools.Runner$$anonfun$runOptionallyWithPassFailReporter$2.apply(Runner.scala:1043)
    at org.scalatest.tools.Runner$.withClassLoaderAndDispatchReporter(Runner.scala:2722)
    at org.scalatest.tools.Runner$.runOptionallyWithPassFailReporter(Runner.scala:1043)
    at org.scalatest.tools.Runner$.run(Runner.scala:883)
    at org.scalatest.tools.Runner.run(Runner.scala)
    at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.runScalaTest2(ScalaTestRunner.java:138)
    at org.jetbrains.plugins.scala.testingSupport.scalaTest.ScalaTestRunner.main(ScalaTestRunner.java:28)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

我的图书馆依赖项是:

libraryDependencies ++= Seq(
  jdbc,
  cache,
  ws,
  "com.typesafe.play"         %% "anorm"               % "2.4.0",
  "com.typesafe.slick"        %% "slick"               % "2.1.0",
  "com.typesafe.play"         %% "play-slick"          % "0.8.0",
  "org.mindrot"               % "jbcrypt"              % "0.3m",
  "joda-time"                 % "joda-time"            % "2.4",
  "org.joda"                  % "joda-convert"         % "1.6",
  "com.github.tototoshi"      %% "slick-joda-mapper"   % "1.2.0",
  "com.typesafe.play.plugins" %% "play-plugins-mailer" % "2.3.1",
  "io.strongtyped"            %% "active-slick"        % "0.2.2",
  "postgresql"                % "postgresql"           % "9.1-901.jdbc4",
  "org.apache.pdfbox"         % "pdfbox"               % "1.8.9",
  "com.opencsv"               % "opencsv"              % "3.5",
  "be.objectify"              %% "deadbolt-scala"      % "2.3.3",
  "org.scalatest"             %% "scalatest"           % "2.2.5"          % "test",
  "org.scalatestplus"         %% "play"                % "1.4.0-M3"       % "test",
  "org.scalacheck"            %% "scalacheck"          % "1.12.4"         % "test",
  "org.specs2"                %% "specs2-core"         % "3.0"            % "test"
)

我的插件是:

// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.3")

// web plugins

addSbtPlugin("com.typesafe.sbt" % "sbt-coffeescript" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-less" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-jshint" % "1.0.1")

addSbtPlugin("com.typesafe.sbt" % "sbt-rjs" % "1.0.1")

addSbtPlugin("com.typesafe.sbt" % "sbt-digest" % "1.0.0")

addSbtPlugin("com.typesafe.sbt" % "sbt-mocha" % "1.0.0")

// Safe Scala Plugins

addSbtPlugin("org.brianmckenna" % "sbt-wartremover" % "0.13")

addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "0.6.0")

addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.8")

// Visualize project's dependencies. (needed to figure out what is forcing scala 2.10)
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.7.5")

// Display your SBT project's dependency updates.
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.8")

addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")

1 个答案:

答案 0 :(得分:1)

问题的根本原因是ObjectMapperPlugin,你可以通过依赖“com.typesafe.play”%%“play-slick”%“0.8.0”来自“com.typesafe.play”%“play_2.10 “%” 2.3.2" 。 Play框架版本2.4.3使用Scala 2.11。所以你应该排除依赖“com.typesafe.play”%“play_2.10”%“2.3.2”。

您应该将导入更改为:

("com.typesafe.play" %% "play-slick" % "0.8.0") .exclude("com.typesafe.play", "play-java_2.10")