你好,当我将表单播放框架2.2.2迁移到2.3.1版本时,我遇到了很大的问题。除了我的班级资产,一切都很好。我正在阅读游戏迁移指南,并试图一步一步地做所有事情,但我仍然不知道该怎么做。
我很抱歉做了很大的帖子,但我想尽可能好地解释它。
迁移之前,当我进入localhost:9000时,一切都很好 我写在这里(在我的页面之前)
编译错误 错误:类中的方法Assets不能应用于给定类型;
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
我展示了警告线。
我花了很多时间试图修复它我已经解决了许多其他问题,结果很好,但是他投降了。
我将非常感谢你的每一次帮助。
答案 0 :(得分:3)
错误消息的原因很明显,在您的代码中,您使用两个参数调用Assets.at
方法。但是Assets.at
的签名是;
public static Action<AnyContent> at(String path,
String file,
boolean aggressiveCaching)
需要三个参数。因此,您需要提供一个布尔值作为调用的第三个参数,以便消除错误消息。
另一方面,我想知道AssetsController
课程的目的。你似乎没有在你的路线中使用它。
关于警告信息;我的建议是用更具体的内容替换GET /*file
规则。由于此规则将匹配所有请求,因此在此规则之后声明的任何规则都不会匹配。然后在您的路径文件末尾声明GET /*file
规则指向返回404响应。
答案 1 :(得分:1)
只是猜测,但线条看起来很可疑:
[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
输入参数冲突,因此问题。我不确定它有多大帮助,我希望我不会造成更多伤害。
答案 2 :(得分:0)
我遇到了同样的问题。您可以按照here所述重新订购路线来修复此问题。
我尝试了添加第三个aggressiveCaching
参数的建议,但这只是在我的路线文件中引起红色波浪形。