can't find favicon.ico issue in play scala

2019-03-01 13:31发布

I have tested a play 2.3.4 app, and in the console it complains the following:

! @6jg7imio5 - Internal server error, for (GET) [/favicon.ico] ->

play.api.Application$$anon$1: Execution exception[[NoSuchElementException: key not found: favicon.ico]]
    at play.api.Application$class.handleError(Application.scala:296) ~[play_2.10-2.3.0.jar:2.3.0]
    at play.api.DefaultApplication.handleError(Application.scala:402) [play_2.10-2.3.0.jar:2.3.0]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$14$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:205) [play_2.10-2.3.0.jar:2.3.0]
    at play.core.server.netty.PlayDefaultUpstreamHandler$$anonfun$14$$anonfun$apply$1.applyOrElse(PlayDefaultUpstreamHandler.scala:202) [play_2.10-2.3.0.jar:2.3.0]
    at scala.runtime.AbstractPartialFunction.apply(AbstractPartialFunction.scala:33) [scala-library.jar:na]
Caused by: java.util.NoSuchElementException: key not found: favicon.ico
    at scala.collection.MapLike$class.default(MapLike.scala:228) ~[scala-library.jar:na]
    at scala.collection.AbstractMap.default(Map.scala:58) ~[scala-library.jar:na]
    at scala.collection.MapLike$class.apply(MapLike.scala:141) ~[scala-library.jar:na]
    at scala.collection.AbstractMap.apply(Map.scala:58) ~[scala-library.jar:na]
    at controllers.Application$$anonfun$list$1$$anonfun$apply$7$$anonfun$apply$8.apply(Application.scala:68) ~[classes/:2.3.0]

Then I searched all the source code and can't find anywhere used favicon.ico. Is it used in some library?

The library I used in slick. The library configuration is as below:

libraryDependencies ++= Seq(
    "com.typesafe.play" %% "play-slick" % "0.7.0",
    "org.slf4j" % "slf4j-nop" % "1.6.4",
    "joda-time" % "joda-time" % "2.3",
    "org.joda" % "joda-convert" % "1.5",
    "com.github.tototoshi" %% "slick-joda-mapper" % "1.1.0",
    jdbc,
    anorm
)

UPDATE:

oracle@SomeHost ~/activator-1.2.10/abb_web_1/public $ tree
.
├── images
│   └── favicon.ico
├── javascripts
│   ├── forms.js
│   └── jquery.js
└── stylesheets
    ├── bootstrap.min.css
    └── main.css

In the route file, I added the following per biesior's reply. But it still complain the same error.Did I put the favicon.ico on the wrong place?

GET     /favicon.ico                controllers.Assets.at(path="/public", file="favicon.ico")

3条回答
Rolldiameter
2楼-- · 2019-03-01 14:01

you should denote the path as controllers.Assets.at(path="/public/images", file="favicon.ico")

查看更多
Deceive 欺骗
3楼-- · 2019-03-01 14:12

Could you be missing the link in your HTML?

<link rel="shortcut icon" href="@routes.Assets.at("images/favicon.ico")">
查看更多
Animai°情兽
4楼-- · 2019-03-01 14:13

Every browser looks for favicon.ico when visiting the address. Just add that file to your public folder and add a route:

GET  /favicon.ico   controllers.Assets.at(path="/public", file="favicon.ico")

TIP: it can be also png file - in default new PlayJava or PlayScala project it can be found in public/images/favicon.png

查看更多
登录 后发表回答