title: Spring with FreeMarker: Could not resolve view with name 'Home' in servlet with name 'MyServlet'
body: <p>I am trying to create a very simple integration of FreeMarker and Spring. However, when I run my example, I get an exception:</p>
  
  <pre><code>GRAVE: Servlet.service() for servlet MyServlet threw exception
  javax.servlet.ServletException: Could not resolve view with name 'Home' in servlet with name 'MyServlet'
      at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1162)
      at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
      at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
      at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
      at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
      at java.lang.Thread.run(Thread.java:662)
  </code></pre>
  
  <p>I don't know what's wrong with my configuration:</p>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextClass&lt;/param-name&gt;
          &lt;param-value&gt;org.springframework.web.context.support.AnnotationConfigWebApplicationContext&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;com.jverstry.Configuration&lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;MyServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;MyServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>Web Configuration</strong></p>
  
  <pre><code>@EnableWebMvc
  @Configuration
  @ComponentScan(basePackages = "com.jverstry")
  public class WebConfig extends WebMvcConfigurerAdapter {
  
      @Bean
      public ViewResolver getViewResolver() {
  
          FreeMarkerViewResolver resolver = new FreeMarkerViewResolver();
          resolver.setCache(true);
          resolver.setPrefix("WEB-INF/pages/");
          resolver.setSuffix(".ftl");
  
          return resolver;
  
      }
  
      @Bean
      public FreeMarkerConfigurer getFreemarkerConfig() {
  
          FreeMarkerConfigurer result = new FreeMarkerConfigurer();
  
          result.setTemplateLoaderPath("WEB-INF/pages/");
  
          return result;
  
      }   
  
  }
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>@Controller
  public class MyController {
  
      @RequestMapping(value = "/")
      public String home(@ModelAttribute("model") ModelMap model) {
  
          model.addAttribute("MsTime", System.currentTimeMillis());
  
          return "Home";
  
      }
  
  }
  </code></pre>
  
  <p><strong>P.S.</strong>: Of course, there is a <code>Home.ftl</code> file in <code>WEB-INF/pages/</code>.</p>