【问题标题】:Play Framework @routes.Assets.at Compilation Error播放框架@routes.Assets.at 编译错误
【发布时间】:2015-08-14 06:31:22
【问题描述】:

我正在使用 Play 2.4.0,我一直在尝试按照主页上的教程进行操作:https://playframework.com/ 这是针对 Play 2.3 的,在解决了 Ebean ORM 从 2.3 版到 2.4 版更改的几个问题后,我遇到了以下错误:

Compilation error

value at is not a member of controllers.ReverseAssets

我的index.scala.html

@(message: String)

@main("Welcome to Play") {

    <script type='text/javascript' src="@routes.Assets.at("javascripts/index.js")"></script>

    <form action="@routes.Application.addPerson()" method="post">
        <input type="text" name="name" />
        <button>Add Person</button>
    </form>

    <ul id="persons">
    </ul>
}

还有我的routes 文件:

# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~

# Home page
GET         /                    controllers.Application.index()

POST        /person              controllers.Application.addPerson()

GET         /persons             controllers.Application.getPersons()

# Map static resources from the /public folder to the /assets URL path
GET         /assets/*file        controllers.Assets.versioned(path="/public", file: Asset)

我有同样的例子在 Play 2.3.9 上运行良好

在 2.4.0 的文档中,我看不出使用公共资产有什么不同:https://www.playframework.com/documentation/2.4.0/Assets

所以...任何帮助将不胜感激。

【问题讨论】:

  • 你尝试运行一次sbt clean 吗?
  • 我试过 activator cleanactivator clean-files 但我得到了同样的错误。
  • IIRC,我在迁移到 2.4 时遇到了类似的错误。我的资产路线如下所示:GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)。注意使用versioned 而不是at。也许这有帮助。如果没有,发布路线配置可能会有所帮助。
  • 忘了提到你还必须在index.scala.html 中将@routes.Assets.at("javascripts/index.js") 更改为@routes.Assets.versioned("javascripts/index.js")
  • @Roman 请创建答案,以便它可以被接受和投票。

标签: java playframework java-8 playframework-2.4


【解决方案1】:

好的,总结一下解决方案:Play 可让您以两种不同的方式提供资产。 sbt-web 引入的老式和新指纹方法。无论哪种情况,请确保您在视图文件中使用正确的调用:

指纹资产

这是投放游戏中资产的推荐方式。指纹资产利用积极的缓存策略。您可以在此处阅读有关此主题的更多信息:https://playframework.com/documentation/2.4.x/Assets

路线配置:

GET     /assets/*file               controllers.Assets.versioned(path="/public", file: Asset)

确保file 的类型指示为Asset

调用视图:

@routes.Assets.versioned("an_asset")


老式资产

这基本上是在引入sbt-web之前使用的方法。

路线配置:

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

调用视图:

@routes.Assets.at("an_asset")

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-19
相关资源
最近更新 更多