【问题标题】:Why does my web app not work after migration from 2.2.2 to 2.3.1?为什么从 2.2.2 迁移到 2.3.1 后我的 Web 应用程序无法运行?
【发布时间】:2014-11-16 10:39:28
【问题描述】:

您好,当我将表单播放框架 2.2.2 迁移到 2.3.1 版本时,我遇到了 Assets 的大问题。除了我的班级资产外,一切都运行良好。我正在阅读 play migrate guide 并尝试逐步完成所有操作,但我仍然不知道该怎么做。

我很抱歉发了这么大的帖子,但我想尽可能地解释它。

在迁移之前一切都很好,当我进入 localhost:9000 我在这里写过(在我有我的页面之前)

编译错误 错误:资产类中的方法不能应用于给定类型;

public class AssetsController extends Controller {

9    public static Action<AnyContent> at(String path, String file) {

10        return Assets.at(path, file); 

11    }

我在终端运行 play ~debug 时收到此错误

[warn] /home/myproject/NewProjectChange/workspace/play-angular/conf/routes:218: patterns
after a variable pattern cannot match (SLS 8.1.1)
[warn] If you intended to match against parameter file of method at, you must use 
backticks, like: case `file` =>
[warn] GET           /*file                                                   
controllers.Assets.at(path="/public", file)
[warn] /home/myproject/NewProjectChange/workspace/play-angular/conf/routes:18: unreachable code due to variable pattern 'file' on line 279
[warn] If you intended to match against parameter file of method at, you must use backticks, like: case `file` =>
[warn] GET           /login                                                  controllers.Assets.at(path="/public", file="login.html")
[warn] /home/myproject/NewProjectChange/workspace/play-angular/conf/routes:26: unreachable code due to variable pattern 'file' on line 279
[warn] If you intended to match against parameter file of method at, you must use backticks, like: case `file` =>
[warn] GET           /page/import                                            controllers.Assets.at(path="/public", file="import.html")
[warn] /home/myproject/NewProjectChange/workspace/play-angular/conf/routes:6: unreachable code due to variable pattern 'file' on line 279
[warn] If you intended to match against parameter file of method at, you must use backticks, like: case `file` =>
[warn] GET           /                                                       controllers.Assets.at(path="/public", file="index.html")
[warn] /home/myproject/NewProjectChange/workspace/play-angular/conf/routes:18: unreachable code
[warn] GET           /login                                                  controllers.Assets.at(path="/public", file="login.html")
[warn] 5 warnings found
[error] /home/myproject/NewProjectChange/workspace/play-angular/app/controllers/AssetsController.java:10: error: method at in class Assets cannot be applied to given types;
[error]         return Assets.at(path, file);
[error]                      ^
[error]   required: String,String,boolean
[error]   found: String,String
[error]   reason: actual and formal argument lists differ in length
[error] /home/myproject/NewProjectChange/workspace/play-angular/app/controllers/AssetsController.java:14: error: method at in class Assets cannot be applied to given types;
[error]         return Assets.at(path, file);
[error]                      ^
[error]   required: String,String,boolean
[error]   found: String,String
[error]   reason: actual and formal argument lists differ in length
[error] /home/myproject/NewProjectChange/workspace/play-angular/app/controllers/AssetsController.java:18: error: method at in class Assets cannot be applied to given types;
[error]         return Assets.at(path, file);
[error]                      ^
[error]   required: String,String,boolean
[error]   found: String,String
[error]   reason: actual and formal argument lists differ in length
[error] /home/myproject/NewProjectChange/workspace/play-angular/app/controllers/AssetsController.java:22: error: method at in class Assets cannot be applied to given types;
[error]         return Assets.at(path, file);
[error]                      ^
[error]   required: String,String,boolean
[error]   found: String,String
[error]   reason: actual and formal argument lists differ in length

我的 build.sbt 文件如下所示:

name := "error"

version := "2.3.1"

lazy val root = (project in file(".")).enablePlugins(PlayJava,SbtWeb)

scalaVersion := "2.11.1"

crossScalaVersions := Seq("2.11.1", "2.10.4")

doc in Compile <<= target.map(_ / "none")

libraryDependencies ++= Seq(
  javaJdbc,
  javaEbean,
  cache,
"com.typesafe.play.plugins" %% "play-plugins-util" % "2.3.0",
"com.typesafe.play.plugins" %% "play-plugins-mailer" % "2.3.0"
)

libraryDependencies += javaWs

libraryDependencies += "mysql" % "mysql-connector-java" % "5.1.24"

libraryDependencies += "org.fusesource.scalate" % "scalate-core" % "1.5.3"

libraryDependencies += "net.sf.opencsv" % "opencsv" % "2.3"

libraryDependencies += "org.apache.thrift" % "libthrift" % "0.9.1"

libraryDependencies += "org.apache.httpcomponents" % "httpclient" % "4.2"

libraryDependencies += "org.apache.httpcomponents" % "httpcore" % "4.2"

libraryDependencies += "org.codehaus.jackson" % "jackson-core-asl" % "1.1.0"

libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.3.1"

我的 plugins.sbt 看起来像:

// Comment to get more information during initialization
logLevel := Level.Warn

// The Typesafe repository
resolvers += "Typesafe repository" at "http://repo.typesafe.com/typesafe/releases/"

// The Typesafe snapshot repository
resolvers += "Typesafe snapshots" at "http://repo.typesafe.com/typesafe/snapshots/"

// Use the Play sbt plugin for Play projects
addSbtPlugin("com.typesafe.play" % "sbt-plugin" % "2.3.1")

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

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

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

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

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

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

例如,我的路线如下所示:

# Map static resources from the /public folder to the /assets URL path
GET           /*file                                                  controllers.Assets.at(path="/public", file) //line 218
GET           /                                                       controllers.Assets.at(path="/public", file="index.html") //line 6
GET           /companies                                              controllers.Assets.at(path="/public", file="index.html")
GET           /login                                                  controllers.Assets.at(path="/public", file="login.html") //line 18

我展示了给出警告的行。

我花了很多时间试图修复它,我已经解决了很多其他问题,效果很好,但我投降了。

我将非常感谢您的每一次帮助。

【问题讨论】:

    标签: playframework sbt playframework-2.3


    【解决方案1】:

    错误消息的原因很明显,在您的代码中您使用两个参数调用Assets.at 方法。但是Assets.at的签名是;

    public static Action<AnyContent> at(String path, 
                                        String file, 
                                        boolean aggressiveCaching)
    

    需要三个参数。因此,您需要提供一个布尔值作为调用的第三个参数,以消除错误消息。

    另一方面,我想知道AssetsController 类的目的。您似乎没有在路线中使用它。

    关于警告信息;我的建议是将GET /*file 规则替换为更具体的规则。由于此规则将匹配所有请求,因此在此之后声明的任何规则都不会匹配。然后在你的路由文件末尾声明 GET /*file 规则指向返回 404 响应。

    【讨论】:

    • 对我帮助很大!谢谢你:)
    【解决方案2】:

    只是猜测,但线条看起来很可疑:

    [warn] /home/myproject/NewProjectChange/workspace/play-angular/conf/routes:218:
    patterns after a variable pattern cannot match (SLS 8.1.1)
    [warn] If you intended to match against parameter file of method at, you must
    use  backticks, like: case `file` =>
    [warn] GET   /*file   controllers.Assets.at(path="/public", file)
    

    方法controllers.Assets.at的签名是:

    def at(path: String, file: String, aggressiveCaching: Boolean = false): Action[AnyContent]
    

    注意file 输入参数。

    我认为它可能会弄乱路线:

    GET   /*file   controllers.Assets.at(path="/public", file)
    

    file 定义为模式。

    我认为file 模式和file 输入参数会发生冲突,因此会出现问题。我不确定它有多大帮助,我希望我不会造成更多伤害。

    【讨论】:

      【解决方案3】:

      我遇到了同样的问题。您可以按照here 所述重新排序路线来修复它。

      我尝试了添加第三个 aggressiveCaching 参数的建议,但这只会在我的路由文件中造成红色波浪线。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-02-07
        • 1970-01-01
        • 2013-12-05
        • 1970-01-01
        • 2019-10-29
        • 1970-01-01
        • 2010-09-30
        • 1970-01-01
        相关资源
        最近更新 更多