title: No favicon.ico for a simple Spring - Maven Web Application
body: <p>I am learning Spring Java Framework, but have the problem with the favicon. I want to get ordinary favicon in the simplest way. I placed the <code>favicon.ico</code> file like this <code>src/main/resources/static/favicon.ico</code>, also tried in just <code>resources</code> folder.</p>
  <p>When I did a deployment to a remote GlassFish 5.1 web server the error happened:</p>
  <p><code>[2020-07-18T02:45:52.695+0200] [glassfish 5.1] [WARNING] [] [org.springframework.web.servlet.PageNotFound] [tid: _ThreadID=696 _ThreadName=http-listener-2(1)] [timeMillis: 1595033152695] [levelValue: 900] [[ No mapping for GET /favicon.ico]]</code></p>
  <p>And no favicon was present on a website.</p>
  <p>At the remote the favicon can be found at this location:
  <code>./glassfish5/glassfish/domains/domain1/applications/HelloSpring-1.0-SNAPSHOT/WEB-INF/classes/static/favicon.ico</code></p>
  <p>Here you are my files</p>
  <p><strong>pom.xml</strong></p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
           xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
           xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;ga.rekano&lt;/groupId&gt;
      &lt;artifactId&gt;HelloSpring&lt;/artifactId&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
          &lt;project.reporting.outputEncoding&gt;UTF-8&lt;/project.reporting.outputEncoding&gt;
      &lt;/properties&gt;
      &lt;dependencies&gt;
          &lt;!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.springframework&lt;/groupId&gt;
              &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
              &lt;version&gt;5.2.7.RELEASE&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api --&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
              &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
              &lt;version&gt;4.0.1&lt;/version&gt;
              &lt;scope&gt;provided&lt;/scope&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  &lt;/project&gt;
  </code></pre>
  <p><strong>Config.java</strong></p>
  <pre><code>package app;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
  
  @Configuration
  @ComponentScan(&quot;app&quot;)
  public class Config extends AbstractAnnotationConfigDispatcherServletInitializer {
      protected Class&lt;?&gt;[] getRootConfigClasses() {
          return new Class[0];
      }
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          return new Class[]{Config.class};
      }
      protected String[] getServletMappings() {
          return new String[]{&quot;/&quot;};
      }
  }
  </code></pre>
  <p><strong>Hello.java</strong></p>
  <pre><code>package app;
  
  import org.springframework.web.bind.annotation.GetMapping;
  import org.springframework.web.bind.annotation.RestController;
  
  @RestController
  public class Hello {
      @GetMapping(&quot;/sayHello&quot;)
      public String sayHello() {
          return &quot;Hello Spring&quot;;
      }
  }
  </code></pre>
  <p>How to get favicon visible?</p>
  <p><strong>edit</strong>
  My question is related to the configuration without files web.xml and mvc-dispatcher-servlet.xml so the answers for questions where these files exist don't solve my problem. I have the very simple application that works and I believe that it is not necessary to add special xml files just to add the favicon. But of course I am a newbie so can be wrong. But on the other hand it is very strange because there are some tutorials where the problem looks like very simple: <a href="https://www.baeldung.com/spring-boot-favicon" rel="nofollow noreferrer">https://www.baeldung.com/spring-boot-favicon</a>
  So the question could be why this simplest method doesn't work in my case?</p>