在尝试从Play 2.2更新到Play 2.4时,我已经遇到了这个绊脚石。
我已经添加了memcached2插件但已禁用。
我的conf文件:
# Cache configuration
# ~~~~~
# To avoid conflict with play2-memcached's Memcached-based cache module
play.modules.disabled+="com.github.mumoshu.play2.memcached.MemcachedModule"
play.modules.enabled+="play.api.cache.EhCacheModule"
# Well-known configuration provided by Play
play.modules.cache.defaultCache=default
play.modules.cache.bindCaches=["db-cache", "user-cache", "session-cache"]
取自github页面上的示例:https://github.com/mumoshu/play2-memcached
build.sbt中的相关部分:
lazy val buildSettings = Seq(
scalaVersion := "2.10.5"
)
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean, SbtTwirl)
.settings(buildSettings: _*)
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
"net.spy" % "spymemcached" % "2.12.0",
"com.github.mumoshu" %% "play2-memcached-play24" % "0.7.0"
)
我得到以下的堆栈跟踪:
play.api.UnexpectedException: Unexpected exception[NoClassDefFoundError: play/api/cache/CachePlugin]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:169) ~[play-server_2.10-2.4.2.jar:2.4.2]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:121) ~[play-server_2.10-2.4.2.jar:2.4.2]
at scala.Option.map(Option.scala:145) ~[scala-library-2.10.5.jar:na]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:121) ~[play-server_2.10-2.4.2.jar:2.4.2]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1.apply(DevServerStart.scala:119) ~[play-server_2.10-2.4.2.jar:2.4.2]
at scala.util.Success.flatMap(Try.scala:200) ~[scala-library-2.10.5.jar:na]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:119) ~[play-server_2.10-2.4.2.jar:2.4.2]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1.apply(DevServerStart.scala:111) ~[play-server_2.10-2.4.2.jar:2.4.2]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1$1(Future.scala:24) ~[scala-library-2.10.5.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library-2.10.5.jar:na]
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402) ~[na:1.8.0_60]
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) ~[na:1.8.0_60]
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) ~[na:1.8.0_60]
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) ~[na:1.8.0_60]
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) ~[na:1.8.0_60]
Caused by: java.lang.NoClassDefFoundError: play/api/cache/CachePlugin
at java.lang.ClassLoader.defineClass1(Native Method) ~[na:1.8.0_60]
at java.lang.ClassLoader.defineClass(ClassLoader.java:760) ~[na:1.8.0_60]
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) ~[na:1.8.0_60]
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467) ~[na:1.8.0_60]
at java.net.URLClassLoader.access$100(URLClassLoader.java:73) ~[na:1.8.0_60]
at java.net.URLClassLoader$1.run(URLClassLoader.java:368) ~[na:1.8.0_60]
at java.net.URLClassLoader$1.run(URLClassLoader.java:362) ~[na:1.8.0_60]
at java.security.AccessController.doPrivileged(Native Method) ~[na:1.8.0_60]
at java.net.URLClassLoader.findClass(URLClassLoader.java:361) ~[na:1.8.0_60]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_60]
at java.lang.ClassLoader.loadClass(ClassLoader.java:411) ~[na:1.8.0_60]
at java.lang.ClassLoader.loadClass(ClassLoader.java:411) ~[na:1.8.0_60]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_60]
at java.lang.Class.forName0(Native Method) ~[na:1.8.0_60]
at java.lang.Class.forName(Class.java:348) ~[na:1.8.0_60]
at play.utils.Reflect$.getClass(Reflect.scala:142) ~[play_2.10-2.4.2.jar:2.4.2]
at play.api.Plugins$$anonfun$loadPlugins$1.apply(Plugins.scala:88) ~[play_2.10-2.4.2.jar:2.4.2]
at play.api.Plugins$$anonfun$loadPlugins$1.apply(Plugins.scala:87) ~[play_2.10-2.4.2.jar:2.4.2]
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library-2.10.5.jar:na]
at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:244) ~[scala-library-2.10.5.jar:na]
at scala.collection.immutable.List.foreach(List.scala:318) ~[scala-library-2.10.5.jar:na]
at scala.collection.TraversableLike$class.map(TraversableLike.scala:244) ~[scala-library-2.10.5.jar:na]
at scala.collection.AbstractTraversable.map(Traversable.scala:105) ~[scala-library-2.10.5.jar:na]
at play.api.Plugins$.loadPlugins(Plugins.scala:87) ~[play_2.10-2.4.2.jar:2.4.2]
at play.api.Plugins$$anonfun$apply$4.apply(Plugins.scala:100) ~[play_2.10-2.4.2.jar:2.4.2]
at play.api.Plugins$$anonfun$apply$4.apply(Plugins.scala:100) ~[play_2.10-2.4.2.jar:2.4.2]
at play.api.Plugins.thePlugins$lzycompute(Plugins.scala:59) ~[play_2.10-2.4.2.jar:2.4.2]
at play.api.Plugins.thePlugins(Plugins.scala:59) ~[play_2.10-2.4.2.jar:2.4.2]
at play.api.Plugins.length(Plugins.scala:60) ~[play_2.10-2.4.2.jar:2.4.2]
at scala.collection.IndexedSeqLike$class.iterator(IndexedSeqLike.scala:91) ~[scala-library-2.10.5.jar:na]
at play.api.Plugins.iterator(Plugins.scala:57) ~[play_2.10-2.4.2.jar:2.4.2]
at scala.collection.IterableLike$class.foreach(IterableLike.scala:72) ~[scala-library-2.10.5.jar:na]
at play.api.Plugins.foreach(Plugins.scala:57) ~[play_2.10-2.4.2.jar:2.4.2]
at play.api.Play$$anonfun$start$1.apply$mcV$sp(Play.scala:92) ~[play_2.10-2.4.2.jar:2.4.2]
at play.api.Play$$anonfun$start$1.apply(Play.scala:87) ~[play_2.10-2.4.2.jar:2.4.2]
at play.api.Play$$anonfun$start$1.apply(Play.scala:87) ~[play_2.10-2.4.2.jar:2.4.2]
at play.utils.Threads$.withContextClassLoader(Threads.scala:21) ~[play_2.10-2.4.2.jar:2.4.2]
at play.api.Play$.start(Play.scala:87) ~[play_2.10-2.4.2.jar:2.4.2]
at play.core.server.DevServerStart$$anonfun$mainDev$1$$anon$1$$anonfun$get$1$$anonfun$apply$1$$anonfun$1.apply(DevServerStart.scala:156) ~[play-server_2.10-2.4.2.jar:2.4.2]
... 14 common frames omitted
Caused by: java.lang.ClassNotFoundException: play.api.cache.CachePlugin
at java.net.URLClassLoader.findClass(URLClassLoader.java:381) ~[na:1.8.0_60]
at java.lang.ClassLoader.loadClass(ClassLoader.java:424) ~[na:1.8.0_60]
at java.lang.ClassLoader.loadClass(ClassLoader.java:357) ~[na:1.8.0_60]
... 53 common frames omitted
我很难过。我从来没有看到这个问题的起源。此外,它似乎旧的"播放依赖"命令,提供了哪个其他依赖项所需的jar版本的漂亮ASCII图表。当前"显示所有依赖关系"只是我在sbt文件中列出的依赖项列表。
编辑:
根据要求,在将所有依赖项更改为2.11.7之后,以及build.sbt文件中的scalaVersion,我得到了这个:
[error] Modules were resolved with conflicting cross-version suffixes in {file:/home/.../}...:
[error] com.typesafe.akka:akka-actor _2.10, _2.11
[error] com.typesafe.play:twirl-api _2.10, _2.11
java.lang.RuntimeException: Conflicting cross-version suffixes in: com.typesafe.akka:akka-actor, com.typesafe.play:twirl-api
at scala.sys.package$.error(package.scala:27)
at sbt.ConflictWarning$.processCrossVersioned(ConflictWarning.scala:46)
at sbt.ConflictWarning$.apply(ConflictWarning.scala:32)
at sbt.Classpaths$$anonfun$66.apply(Defaults.scala:1164)
at sbt.Classpaths$$anonfun$66.apply(Defaults.scala:1161)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
at sbt.std.Transform$$anon$4.work(System.scala:63)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.Execute.work(Execute.scala:235)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[error] (*:update) Conflicting cross-version suffixes in: com.typesafe.akka:akka-actor, com.typesafe.play:twirl-api
EDIT2: build.properties:
sbt.version=0.13.8
plugins.sbt:
// Comment to get more information during initialization
logLevel := Level.Warn
// The Play plugin
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.4.2")
// The Typesafe repository
resolvers ++= Seq(
"Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/",
"Public SBT repo" at "http://dl.bintray.com/sbt/sbt-plugin-releases/",
"Local maven repo" at "file://"+Path.userHome.absolutePath+"/.m2/repository"
)
// The eclipse plugin
addSbtPlugin("com.typesafe.sbteclipse" % "sbteclipse-plugin" % "4.0.0")
// Play enhancer - this automatically generates getters/setters for public fields
// and rewrites accessors of these fields to use the getters/setters. Remove this
// plugin if you prefer not to have this feature, or disable on a per project
// basis using disablePlugins(PlayEnhancer) in your build.sbt
addSbtPlugin("com.typesafe.sbt" % "sbt-play-enhancer" % "1.1.0")
// Play Ebean support, to enable, uncomment this line, and enable in your build.sbt using
// enablePlugins(SbtEbean). Note, uncommenting this line will automatically bring in
// Play enhancer, regardless of whether the line above is commented out or not.
addSbtPlugin("com.typesafe.sbt" % "sbt-play-ebean" % "1.0.0")
build.sbt:
lazy val buildSettings = Seq(
scalaVersion := "2.11.7"
)
lazy val root = (project in file(".")).enablePlugins(PlayJava, PlayEbean, SbtTwirl)
.settings(buildSettings: _*)
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs,
"net.spy" % "spymemcached" % "2.12.0",
"com.github.mumoshu" %% "play2-memcached-play24" % "0.7.0",
"org.apache.commons" % "commons-collections4" % "4.0"
)
EDIT2:从build.sbt中删除SbtTwirl后的输出:
[error] Modules were resolved with conflicting cross-version suffixes in {file:/home/.../}...:
[error] com.typesafe.play:play-ws _2.11, _2.10
[error] com.typesafe.play:play-functional _2.11, _2.10
[error] com.typesafe.akka:akka-actor _2.11, _2.10
[error] com.typesafe.play:play-java-ws _2.11, _2.10
[error] com.typesafe.play:play-json _2.11, _2.10
[error] com.typesafe.play:play _2.11, _2.10
[error] com.typesafe.play:play-cache _2.11, _2.10
[error] com.typesafe.play:play-server _2.11, _2.10
[error] com.typesafe.play:play-java-jdbc _2.11, _2.10
[error] com.typesafe.play:play-iteratees _2.11, _2.10
[error] com.typesafe.play:twirl-api _2.11, _2.10
[error] com.typesafe.play:play-jdbc _2.11, _2.10
[error] com.typesafe.play:play-java _2.11, _2.10
[error] com.typesafe.play:play-netty-server _2.11, _2.10
[error] org.scala-lang.modules:scala-java8-compat _2.11, _2.10
[error] com.typesafe.akka:akka-slf4j _2.11, _2.10
[error] org.scala-stm:scala-stm _2.11, _2.10
[error] com.github.mumoshu:play2-memcached-play24 _2.11, _2.10
[error] com.typesafe.play:play-datacommons _2.11, _2.10
[error] com.typesafe.play:play-jdbc-api _2.11, _2.10
java.lang.RuntimeException: Conflicting cross-version suffixes in: com.typesafe.play:play-ws, com.typesafe.play:play-functional, com.typesafe.akka:akka-actor, com.typesafe.play:play-java-ws, com.typesafe.play:play-json, com.typesafe.play:play, com.typesafe.play:play-cache, com.typesafe.play:play-server, com.typesafe.play:play-java-jdbc, com.typesafe.play:play-iteratees, com.typesafe.play:twirl-api, com.typesafe.play:play-jdbc, com.typesafe.play:play-java, com.typesafe.play:play-netty-server, org.scala-lang.modules:scala-java8-compat, com.typesafe.akka:akka-slf4j, org.scala-stm:scala-stm, com.github.mumoshu:play2-memcached-play24, com.typesafe.play:play-datacommons, com.typesafe.play:play-jdbc-api
at scala.sys.package$.error(package.scala:27)
at sbt.ConflictWarning$.processCrossVersioned(ConflictWarning.scala:46)
at sbt.ConflictWarning$.apply(ConflictWarning.scala:32)
at sbt.Classpaths$$anonfun$66.apply(Defaults.scala:1164)
at sbt.Classpaths$$anonfun$66.apply(Defaults.scala:1161)
at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
at sbt.std.Transform$$anon$4.work(System.scala:63)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
at sbt.Execute.work(Execute.scala:235)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
[error] (*:update) Conflicting cross-version suffixes in: com.typesafe.play:play-ws, com.typesafe.play:play-functional, com.typesafe.akka:akka-actor, com.typesafe.play:play-java-ws, com.typesafe.play:play-json, com.typesafe.play:play, com.typesafe.play:play-cache, com.typesafe.play:play-server, com.typesafe.play:play-java-jdbc, com.typesafe.play:play-iteratees, com.typesafe.play:twirl-api, com.typesafe.play:play-jdbc, com.typesafe.play:play-java, com.typesafe.play:play-netty-server, org.scala-lang.modules:scala-java8-compat, com.typesafe.akka:akka-slf4j, org.scala-stm:scala-stm, com.github.mumoshu:play2-memcached-play24, com.typesafe.play:play-datacommons, com.typesafe.play:play-jdbc-api
答案 0 :(得分:1)
我认为你需要启用MemCachedModule和Disable EhCacheModule
play.modules.enabled+="com.github.mumoshu.play2.memcached.MemcachedModule"
play.modules.disabled+="play.api.cache.EhCacheModule"
请查看配置@ https://github.com/mumoshu/play2-memcached
另一个建议是:
Play在2.4中工作,与2.2完全不同。 Guice DI进入初始化已完全改变。
插件应该迁移到模块。
Play 2.4。*之后没有CachePlugin类
播放告诉:
注意:Scala 2.10并不完全支持所有Java 8语言功能,例如接口上的静态方法。如果您的项目使用Java 8中提供的这些新功能使用Java代码,请升级以使用Scala 2.11.6+。请参阅sbt docs以了解如何将scalaVersion设置为您的项目。
答案 1 :(得分:0)
如果您使用的是Play 2.4,则应将scala版本更改为2.11。这可能是造成你的依赖问题的原因。
答案 2 :(得分:0)
我建议您先尝试升级到Play 2.3.x.一旦它全部好,那么,升级到2.4.x. 单独的2.3和2.4之间的差异是相当大的,我记得我必须在某些时候从Build.scala切换到build.sbt
因此,在您进行增量升级之前,您可能会注意到一些冲突。