在 controllers.WebJarAssets 中找不到合适的构造函数
Could not find a suitable constructor in controllers.WebJarAssets
我有一个简单的播放框架应用程序。我添加了 webjars 依赖项来处理我添加的一些 bootstrap 库。当我尝试访问我的资源表单屏幕之一时,我不断收到以下错误。
play.api.UnexpectedException: Unexpected exception[ProvisionException: Unable to provision, see the following errors:
1) Could not find a suitable constructor in controllers.WebJarAssets. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
at controllers.WebJarAssets.class(WebJarAssets.scala:18)
while locating controllers.WebJarAssets
for parameter 4 at router.Routes.<init>(Routes.scala:40)
while locating router.Routes
while locating play.api.inject.RoutesProvider
while locating play.api.routing.Router
1 error]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get$$anonfun$apply$$anonfun.apply(DevServerStart.scala:165) ~[play-server_2.11-2.4.6.jar:2.4.6]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get$$anonfun$apply$$anonfun.apply(DevServerStart.scala:121) ~[play-server_2.11-2.4.6.jar:2.4.6]
at scala.Option.map(Option.scala:146) ~[scala-library.jar:na]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get$$anonfun$apply.apply(DevServerStart.scala:121) ~[play-server_2.11-2.4.6.jar:2.4.6]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get$$anonfun$apply.apply(DevServerStart.scala:119) ~[play-server_2.11-2.4.6.jar:2.4.6]
at scala.util.Success.flatMap(Try.scala:230) ~[scala-library.jar:na]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get.apply(DevServerStart.scala:119) ~[play-server_2.11-2.4.6.jar:2.4.6]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get.apply(DevServerStart.scala:111) ~[play-server_2.11-2.4.6.jar:2.4.6]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1(Future.scala:24) ~[scala-library.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library.jar:na]
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402) ~[na:1.8.0_60]
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) ~[na:1.8.0_60]
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) ~[na:1.8.0_60]
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) ~[na:1.8.0_60]
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) ~[na:1.8.0_60]
Caused by: com.google.inject.ProvisionException: Unable to provision, see the following errors:
这是我的 sbt 文件。
name := """PlankTeamAwards"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.6"
libraryDependencies += evolutions
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs
)
libraryDependencies ++= Seq(
"org.webjars" %% "webjars-play" % "2.3.0-2",
"org.webjars" % "bootstrap" % "3.3.2"
)
// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator
这是我的路线文件
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET / controllers.Application.index()
GET /hello controllers.Application.hello(name:String)
# Employees
GET /employees/ controllers.Employees.list()
GET /employees/new controllers.Employees.showBlank()
GET /employees/:employeeId controllers.Employees.show(employeeId: Long)
POST /employees/ controllers.Employees.save()
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
GET /webjars/*file controllers.WebJarAssets.at(file)
这是我的 main.scala.html 文件,我在其中引用了 boostrap css 文件。
@(title: String)(content: Html)
<!DOCTYPE html>
<html lang="en">
<head>
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
<link rel='stylesheet' href='@routes.WebJarAssets.at(WebJarAssets.locate("css/bootstrap.min.css"))'>
<script src="@routes.Assets.versioned("javascripts/hello.js")" type="text/javascript"></script>
</head>
<body>
@content
</body>
</html>
您需要升级到最新的webjars-play
:
"org.webjars" %% "webjars-play" % "2.4.0-2"
我有一个简单的播放框架应用程序。我添加了 webjars 依赖项来处理我添加的一些 bootstrap 库。当我尝试访问我的资源表单屏幕之一时,我不断收到以下错误。
play.api.UnexpectedException: Unexpected exception[ProvisionException: Unable to provision, see the following errors:
1) Could not find a suitable constructor in controllers.WebJarAssets. Classes must have either one (and only one) constructor annotated with @Inject or a zero-argument constructor that is not private.
at controllers.WebJarAssets.class(WebJarAssets.scala:18)
while locating controllers.WebJarAssets
for parameter 4 at router.Routes.<init>(Routes.scala:40)
while locating router.Routes
while locating play.api.inject.RoutesProvider
while locating play.api.routing.Router
1 error]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get$$anonfun$apply$$anonfun.apply(DevServerStart.scala:165) ~[play-server_2.11-2.4.6.jar:2.4.6]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get$$anonfun$apply$$anonfun.apply(DevServerStart.scala:121) ~[play-server_2.11-2.4.6.jar:2.4.6]
at scala.Option.map(Option.scala:146) ~[scala-library.jar:na]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get$$anonfun$apply.apply(DevServerStart.scala:121) ~[play-server_2.11-2.4.6.jar:2.4.6]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get$$anonfun$apply.apply(DevServerStart.scala:119) ~[play-server_2.11-2.4.6.jar:2.4.6]
at scala.util.Success.flatMap(Try.scala:230) ~[scala-library.jar:na]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get.apply(DevServerStart.scala:119) ~[play-server_2.11-2.4.6.jar:2.4.6]
at play.core.server.DevServerStart$$anonfun$mainDev$$anon$$anonfun$get.apply(DevServerStart.scala:111) ~[play-server_2.11-2.4.6.jar:2.4.6]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.liftedTree1(Future.scala:24) ~[scala-library.jar:na]
at scala.concurrent.impl.Future$PromiseCompletingRunnable.run(Future.scala:24) ~[scala-library.jar:na]
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1402) ~[na:1.8.0_60]
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289) ~[na:1.8.0_60]
at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056) ~[na:1.8.0_60]
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692) ~[na:1.8.0_60]
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157) ~[na:1.8.0_60]
Caused by: com.google.inject.ProvisionException: Unable to provision, see the following errors:
这是我的 sbt 文件。
name := """PlankTeamAwards"""
version := "1.0-SNAPSHOT"
lazy val root = (project in file(".")).enablePlugins(PlayJava)
scalaVersion := "2.11.6"
libraryDependencies += evolutions
libraryDependencies ++= Seq(
javaJdbc,
cache,
javaWs
)
libraryDependencies ++= Seq(
"org.webjars" %% "webjars-play" % "2.3.0-2",
"org.webjars" % "bootstrap" % "3.3.2"
)
// Play provides two styles of routers, one expects its actions to be injected, the
// other, legacy style, accesses its actions statically.
routesGenerator := InjectedRoutesGenerator
这是我的路线文件
# Routes
# This file defines all application routes (Higher priority routes first)
# ~~~~
# Home page
GET / controllers.Application.index()
GET /hello controllers.Application.hello(name:String)
# Employees
GET /employees/ controllers.Employees.list()
GET /employees/new controllers.Employees.showBlank()
GET /employees/:employeeId controllers.Employees.show(employeeId: Long)
POST /employees/ controllers.Employees.save()
# Map static resources from the /public folder to the /assets URL path
GET /assets/*file controllers.Assets.versioned(path="/public", file: Asset)
GET /webjars/*file controllers.WebJarAssets.at(file)
这是我的 main.scala.html 文件,我在其中引用了 boostrap css 文件。
@(title: String)(content: Html)
<!DOCTYPE html>
<html lang="en">
<head>
<title>@title</title>
<link rel="stylesheet" media="screen" href="@routes.Assets.versioned("stylesheets/main.css")">
<link rel="shortcut icon" type="image/png" href="@routes.Assets.versioned("images/favicon.png")">
<link rel='stylesheet' href='@routes.WebJarAssets.at(WebJarAssets.locate("css/bootstrap.min.css"))'>
<script src="@routes.Assets.versioned("javascripts/hello.js")" type="text/javascript"></script>
</head>
<body>
@content
</body>
</html>
您需要升级到最新的webjars-play
:
"org.webjars" %% "webjars-play" % "2.4.0-2"