Play Framework @ routes.Assets.at编译错误

Dan*_*ero 36 java playframework java-8 playframework-2.4

我正在使用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
Run Code Online (Sandbox Code Playgroud)

我的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>
}
Run Code Online (Sandbox Code Playgroud)

我的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)
Run Code Online (Sandbox Code Playgroud)

我有这个相同的例子与Play 2.3.9正常工作

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

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

Rom*_*man 68

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

指纹资产

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

路由配置:

GET     /assets/*file               controllers.Assets.versioned(path="/public", file: Asset)
Run Code Online (Sandbox Code Playgroud)

确保类型file指示为Asset

来电观点:

@routes.Assets.versioned("an_asset")
Run Code Online (Sandbox Code Playgroud)


老式资产

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

路由配置:

GET     /assets/*file               controllers.Assets.at(path="/public", file)
Run Code Online (Sandbox Code Playgroud)

来电观点:

@routes.Assets.at("an_asset")
Run Code Online (Sandbox Code Playgroud)

  • IntelliJ错误地将Assets.versioned()报告为已弃用,尚未修复,请参阅https://youtrack.jetbrains.com/issue/SCL-8812 (3认同)