2017-10-20 35 views
1

我有瀏覽器緩存的問題,所以我決定改變斯卡拉玩`@ routes.Assets.versioned`導致非描述性錯誤

<script type="text/javascript" src="@routes.Assets.at("/accounts/dist/inline.bundle.js")"></script> 

<script type="text/javascript" src="@routes.Assets.versioned("/public/accounts/dist","inline.bundle.js")"></script> 

因爲我們已經做在其他項目中,但我得到這完全無益的錯誤:

C:\work\FrontServices\Spike2>sbt -jvm-debug 9999 run 
"C:\Users\xavier\.sbt\preloaded\org.scala-sbt\sbt\"1.0.2"\jars\sbt.jar" 
Picked up JAVA_TOOL_OPTIONS: -Dfile.encoding=UTF8 
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=256m; support was removed in 8.0 
Listening for transport dt_socket at address: 58387 
[warn] Executing in batch mode. 
[warn] For better performance, hit [ENTER] to switch to interactive mode, or 
[warn] consider launching sbt without any commands, or explicitly passing 'shell' 
[info] Loading project definition from C:\Users\xavier\.sbt\0.13\staging\560eb781744c869bfbb7\sbt-coveralls\project 
[info] Loading project definition from C:\work\FrontServices\Spike2\project 
[info] Set current project to Spike2 (in build file:/C:/work/FrontServices/Spike2/) 
[info] Compiling 1 Scala source to C:\work\FrontServices\Spike2\modules\accounts\target\scala-2.11\classes... 
[error] C:\work\FrontServices\Spike2\modules\accounts\app\com\newswhip\accounts\views\accounts.scala.html:20: too many arguments for method versioned: (file: controllers.Assets.Asset)play.api.mvc.Call 
[error]  <script type="text/javascript" src="@routes.Assets.versioned("/public/accounts/dist","inline.bundle.js")"></script> 
[error]                     ^
[error] C:\work\FrontServices\Spike2\modules\accounts\app\com\newswhip\accounts\views\accounts.scala.html:21: too many arguments for method versioned: (file: controllers.Assets.Asset)play.api.mvc.Call 
[error]  <script type="text/javascript" src="@routes.Assets.versioned("/public/accounts/dist","polyfills.bundle.js")"></script> 
[error]                     ^
[error] C:\work\FrontServices\Spike2\modules\accounts\app\com\newswhip\accounts\views\accounts.scala.html:22: too many arguments for method versioned: (file: controllers.Assets.Asset)play.api.mvc.Call 
[error]  <script type="text/javascript" src="@routes.Assets.versioned("/public/accounts/dist","styles.bundle.js")"></script> 
[error]                     ^
[error] C:\work\FrontServices\Spike2\modules\accounts\app\com\newswhip\accounts\views\accounts.scala.html:23: too many arguments for method versioned: (file: controllers.Assets.Asset)play.api.mvc.Call 
[error]  <script type="text/javascript" src="@routes.Assets.versioned("/public/accounts/dist","vendor.bundle.js")"></script> 
[error]                      ^
[error] C:\work\FrontServices\Spike2\modules\accounts\app\com\newswhip\accounts\views\accounts.scala.html:24: too many arguments for method versioned: (file: controllers.Assets.Asset)play.api.mvc.Call 
[error]  <script type="text/javascript" src="@routes.Assets.versioned("/public/accounts/dist","main.bundle.js")"></script> 
[error]                      ^
[error] 5 errors found 
[error] (accounts/compile:compileIncremental) Compilation failed 
[error] Total time: 4 s, completed 20-Oct-2017 10:27:09 

C:\work\FrontServices\Spike2> 

這是從代碼片段文件

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

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

任何想法?

回答

0

src="@routes.Assets.versioned("/public/accounts/dist","inline.bundle.js")" 你爲什麼要在versioned()中用逗號分隔兩個字符串。

這意味着你給versioned()兩個參數,因爲它只是拋出一個錯誤,因爲它只有一個。

相反,你應該給它這樣的 -

src="@routes.Assets.versioned("/public/accounts/dist/inline.bundle.js")" 

假設inline.bundle.js在路徑/public/accounts/dist/

嘗試了這一點,讓我知道,如果它的工作原理。我希望它!

+0

我傳遞2個參數的int版本,因爲我們都已經在做了成功的其他2個項目。除了路徑文件在'GET/assets/*文件controllers.Assets.versioned(path =「/ public/accounts/dist」,file:Asset)中有這樣的一行外,所以版本化可能需要2個參數。我已經嘗試將param合併到1字符串中,就像用於' - 剛剛用'版本'代替'at',但編譯時出現「noSuchMethod + controllers.ReverseAssets.versioned」錯誤。 – codeepic

+0

確切的錯誤是從線程[application-akka.actor.default-dispatcher-6]的未捕獲錯誤關閉JVM,因爲爲ActorSystem [application] java啓用了'akka.jvm-exit-on-fatal-error'。 lang.NoSuchMethodError:controllers.ReverseAssets.versioned(Lcontrollers/Assets $ Asset;)Lplay/api/mvc/Call;' – codeepic

+0

好的,嘗試從版本中刪除已經在路由中給出的路徑。我的意思是,在路由中你指定了路徑爲'/ public/accounts/dist',然後在代碼中訪問時刪除這部分。嘗試使用 - 'src =「@ routes.Assets.versioned(」inline.bundle.js「)」'。我希望它能起作用! –

0

在你routes定義你正在做的:

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

這意味着對方法Assets.versioned的第一個參數已經被定義(path = "/public/accounts/dist")。所以,你只有一個參數的空間(資產文件)。但在你的觀點,你有:

<script type="text/javascript" src="@routes.Assets.versioned("/public/accounts/dist","inline.bundle.js")"></script> 

換句話說,你正試圖再次定義路徑,但這是產生反向路由器現在(@routes.Assets),而不是「原裝」 Assets.versioned,那麼你得到的錯誤。

的解決方案是修改代碼,僅傳遞file參數:

<script type="text/javascript" src="@routes.Assets.versioned("inline.bundle.js")"></script>