1

我刚刚从现有项目的 2.0 迁移到 Play Framework 2.1-RC1,由于某种原因,我现在必须在渲染视图时将所有内容从 Java 类转换为 Scala 类。(显然我在 Java 项目而不是 Scala 项目中使用 Play)

下面是一个示例错误...

render(java.lang.String,scala.collection.immutable.List<models.User>) in views.html.list cannot be applied to (java.lang.String,java.util.List<models.User>)

而我的观点最重要的是......

@(message: String, users : List[models.User])

据此,我推测由于某种原因,类不会自动java.util.List转换为等效的 scala。在这个阶段,我是 Java 人,而不是 Scala 人,所以我可能会做一些愚蠢的事情。

调用渲染的示例代码...

public static Result list() {
        List<User> users = MorphiaManager.getDatastore().find(User.class).asList();
    System.out.println("about to try to display list of " + users.size() + " users");
        return ok(list.render("Welcome", msgs));
    }

Build.scala 下面

import sbt._
import Keys._
import PlayProject._

object ApplicationBuild extends Build {

    val appName         = "blah-worker"
    val appVersion      = "1.0-SNAPSHOT"

    val appDependencies = Seq(
  // Play framework dependencies
  javaCore, javaJdbc, javaEbean,
  // Add your project dependencies here,
  "org.apache.camel" % "camel-core" % "2.10.0",
  "org.apache.camel" % "camel-jms" % "2.10.0",
  "org.apache.camel" % "camel-mail" % "2.10.0",
  "org.apache.camel" % "camel-jackson" % "2.10.0",
  "org.apache.camel" % "camel-gson" % "2.10.0",
  "org.apache.activemq" % "activemq-core" % "5.6.0",
  "org.apache.activemq" % "activemq-camel" % "5.6.0",
  "org.apache.activemq" % "activemq-pool" % "5.6.0",
  "com.google.code.morphia" % "morphia" % "0.99.1-SNAPSHOT",
  "com.google.code.morphia" % "morphia-logging-slf4j" % "0.99",
  "cglib" % "cglib-nodep" % "[2.1_3,)",
  "com.thoughtworks.proxytoys" % "proxytoys" % "1.0",
  "org.apache.james" % "apache-mime4j" % "0.7.2",
  ("org.jclouds" % "jclouds-allblobstore" % "1.5.0-beta.4").exclude("com.google.guava", "guava").exclude("org.reflections", "reflections"),
  ("org.reflections"                  %    "reflections"              %   "0.9.7").exclude("com.google.guava", "guava").exclude("javassist", "javassist")
)

val main = play.Project(appName, appVersion, appDependencies).settings(
  // Add your own project settings here
  resolvers += "Morphia repo" at "http://morphia.googlecode.com/svn/mavenrepo/",
  resolvers += "CodeHaus for ProxyToys" at "http://repository.codehaus.org/",
  checksums := Nil
)

}
4

3 回答 3

1

您是否缺少新的“javaCore”依赖项?使用 Play 2.1 的 Java 项目需要它。在此处查看迁移详细信息:

https://github.com/playframework/Play20/wiki/Migration

于 2012-12-07T18:54:34.563 回答
1

想通了,我没有更新Build.scala.

具体来说...

import PlayProject._

应该更新到...

import play.Project._

这在迁移指南中也有详细说明(但我错过了):https ://github.com/playframework/Play20/wiki/Migration

于 2012-12-08T04:14:02.793 回答
0

我不确定它是否会解决您的问题,但您可以尝试添加此导入:

import scala.collection.JavaConversions.*;

于 2012-12-01T18:51:08.873 回答