title: Spring MVC: HTTP status 404: The requested resource is not available
body: <p>I am new to Spring MVC. I am trying to integrate Thymeleaf with Spring 4, and I wrote a helloworld program with one controler/metho. However, when I start Tomcat, I got this error when accessing <code>http://localhost:8080/hello</code></p>
  
  <pre><code>HTTP Status 404 -
  
  type Status report
  
  message
  
  description The requested resource is not available.
  </code></pre>
  
  <p>In my pom.xml file, I have the following: </p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
    &lt;groupId&gt;homeMadeSpring&lt;/groupId&gt;
    &lt;artifactId&gt;homeMadeSpringFirst&lt;/artifactId&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    &lt;name&gt;homeMadeSpringFirst&lt;/name&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
  
    &lt;properties&gt;
      &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;spring.version&gt;4.0.5.RELEASE&lt;/spring.version&gt;
        &lt;spring.security.version&gt;3.2.4.RELEASE&lt;/spring.security.version&gt;
    &lt;/properties&gt;
  
    &lt;dependencies&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;junit&lt;/groupId&gt;
        &lt;artifactId&gt;junit&lt;/artifactId&gt;
        &lt;version&gt;3.8.1&lt;/version&gt;
        &lt;scope&gt;test&lt;/scope&gt;
      &lt;/dependency&gt;
  
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-context&lt;/artifactId&gt;
            &lt;version&gt;${spring.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-aop&lt;/artifactId&gt;
            &lt;version&gt;${spring.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework&lt;/groupId&gt;
            &lt;artifactId&gt;spring-webmvc&lt;/artifactId&gt;
            &lt;version&gt;${spring.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.thymeleaf&lt;/groupId&gt;
            &lt;artifactId&gt;thymeleaf&lt;/artifactId&gt;
            &lt;version&gt;2.1.2.RELEASE&lt;/version&gt;
            &lt;scope&gt;compile&lt;/scope&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.thymeleaf&lt;/groupId&gt;
            &lt;artifactId&gt;thymeleaf-spring4&lt;/artifactId&gt;
            &lt;version&gt;2.1.2.RELEASE&lt;/version&gt;
        &lt;/dependency&gt;
  
        &lt;dependency&gt;
            &lt;groupId&gt;joda-time&lt;/groupId&gt;
            &lt;artifactId&gt;joda-time&lt;/artifactId&gt;
            &lt;version&gt;2.1&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
            &lt;artifactId&gt;spring-security-core&lt;/artifactId&gt;
            &lt;version&gt;${spring.security.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
            &lt;artifactId&gt;spring-security-config&lt;/artifactId&gt;
            &lt;version&gt;${spring.security.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
            &lt;artifactId&gt;spring-security-web&lt;/artifactId&gt;
            &lt;version&gt;${spring.security.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;org.springframework.security&lt;/groupId&gt;
            &lt;artifactId&gt;spring-security-taglibs&lt;/artifactId&gt;
            &lt;version&gt;${spring.security.version}&lt;/version&gt;
        &lt;/dependency&gt;
        &lt;dependency&gt;
            &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
            &lt;artifactId&gt;javax.servlet-api&lt;/artifactId&gt;
            &lt;version&gt;3.0.1&lt;/version&gt;
        &lt;/dependency&gt;
    &lt;/dependencies&gt;
      &lt;build&gt;
          &lt;finalName&gt;homeMadeSpringFirst&lt;/finalName&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.3.2&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.8&lt;/source&gt;
                      &lt;target&gt;1.8&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.1.1&lt;/version&gt;
              &lt;/plugin&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.mortbay.jetty&lt;/groupId&gt;
                  &lt;artifactId&gt;jetty-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;8.1.2.v20120308&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;webAppConfig&gt;
                          &lt;contextPath&gt;/homemade&lt;/contextPath&gt;
                      &lt;/webAppConfig&gt;
                      &lt;scanIntervalSeconds&gt;1&lt;/scanIntervalSeconds&gt;
                      &lt;stopKey&gt;stop-jetty&lt;/stopKey&gt;
                      &lt;stopPort&gt;9999&lt;/stopPort&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;s
  &lt;/project&gt;
  </code></pre>
  
  <p>In my src/main/resources directory, I have two files: applicationContext-security.xml, and thymeleaf-pages.xml.</p>
  
  <p><strong>The content of applicationContext-security.xml is:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/security"
               xmlns:beans="http://www.springframework.org/schema/beans"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:context="http://www.springframework.org/schema/context"
               xsi:schemaLocation="http://www.springframework.org/schema/beans
             http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
             http://www.springframework.org/schema/security
             http://www.springframework.org/schema/security/spring-security-3.2.xsd
             http://www.springframework.org/schema/context
             http://www.springframework.org/schema/context/spring-context-4.0.xsd"&gt;
  
  
      &lt;http pattern="/login" security="none"/&gt;
      &lt;http pattern="/assets/**" security="none"/&gt;
  
      &lt;http auto-config="true" use-expressions="true"&gt;
          &lt;intercept-url pattern="/homeMadeSpring" access="isAuthenticated()" /&gt;
  
          &lt;form-login
                  login-processing-url="/authentication"
                  login-page="/login"
                  authentication-failure-url="/login?error=true"
                  default-target-url="/hello"
                  always-use-default-target="false"
                  /&gt;
          &lt;remember-me user-service-ref="userDetailsService"/&gt;
          &lt;logout logout-url="/logout"
                  logout-success-url="/login"/&gt;
      &lt;/http&gt;
  
      &lt;authentication-manager&gt;
          &lt;authentication-provider user-service-ref="userDetailsService"/&gt;
      &lt;/authentication-manager&gt;
  
  
      &lt;user-service id="userDetailsService"&gt;
          &lt;user name="admin" password="admin" authorities="ROLE_USER"/&gt;
      &lt;/user-service&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>**In my thyme-pages.xml, I have: **</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns:context="http://www.springframework.org/schema/context"
         xmlns:mvc="http://www.springframework.org/schema/mvc"
         xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd"&gt;
  
  
      &lt;mvc:resources location="/assets/img/" mapping="/assets/img/**" /&gt;
      &lt;mvc:resources location="/assets/css/" mapping="/assets/css/**" /&gt;
      &lt;mvc:resources location="/assets/js/" mapping="/assets/js/**" /&gt;
  
  
      &lt;bean id="httpMessageConverter" class="org.springframework.http.converter.StringHttpMessageConverter"&gt;
          &lt;property name="supportedMediaTypes" value = "text/plain;charset=UTF-8" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="defaultMessageConverters" class="java.util.ArrayList"&gt;
          &lt;constructor-arg&gt;
              &lt;list&gt;
                  &lt;ref bean="httpMessageConverter"/&gt;
              &lt;/list&gt;
          &lt;/constructor-arg&gt;
      &lt;/bean&gt;
  
      &lt;bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter" &gt;
          &lt;property name="messageConverters" ref="defaultMessageConverters"/&gt;
          &lt;property name="cacheSeconds" value="0"/&gt; &lt;!--  NO CACHE  --&gt;
      &lt;/bean&gt;
  
  
      &lt;bean id="homeController" class="controllers.HomeController"/&gt;
  
  
      &lt;bean id="contentNegotiatingResolver" class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver"&gt;
          &lt;property name="mediaTypes"&gt;
              &lt;map&gt;
                  &lt;entry key="html" value="text/html"/&gt;
                  &lt;entry key="pdf" value="application/pdf"/&gt;
                  &lt;entry key="xsl" value="application/vnd.ms-excel"/&gt;
                  &lt;entry key="xml" value="application/xml"/&gt;
                  &lt;entry key="json" value="application/json"/&gt;
              &lt;/map&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="templateResolver" class="org.thymeleaf.templateresolver.ServletContextTemplateResolver"&gt;
          &lt;property name="prefix" value="/" /&gt;
          &lt;property name="suffix" value=".html" /&gt;
          &lt;property name="templateMode" value="HTML5" /&gt;
          &lt;property name="cacheable" value="false"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine"&gt;
          &lt;property name="templateResolver" ref="templateResolver" /&gt;
      &lt;/bean&gt;
  
  
      &lt;bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver"&gt;
          &lt;property name="templateEngine" ref="templateEngine" /&gt;
          &lt;property name="characterEncoding" value="UTF-8"/&gt;
      &lt;/bean&gt;
  
      &lt;bean id="dateFormatter" class="util.DateFormatter"/&gt;
  
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>In src/main/webapp/WEB-INF directory, my web.xml has the following:</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt;
      &lt;display-name&gt;HelloWorld&lt;/display-name&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  
      &lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;classpath:applicationContext-security.xml&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;HelloWorld&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;classpath:thymeleaf-pages.xml&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;HelloWorld&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
      &lt;filter&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.DelegatingFilterProxy&lt;/filter-class&gt;
      &lt;/filter&gt;
  
      &lt;filter&gt;
          &lt;filter-name&gt;characterEncodingFilter&lt;/filter-name&gt;
          &lt;filter-class&gt;org.springframework.web.filter.CharacterEncodingFilter&lt;/filter-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;encoding&lt;/param-name&gt;
              &lt;param-value&gt;UTF-8&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;forceEncoding&lt;/param-name&gt;
              &lt;param-value&gt;true&lt;/param-value&gt;
          &lt;/init-param&gt;
      &lt;/filter&gt;
  
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;characterEncodingFilter&lt;/filter-name&gt;
          &lt;url-pattern&gt;/pages/*&lt;/url-pattern&gt;
      &lt;/filter-mapping&gt;
      &lt;filter-mapping&gt;
          &lt;filter-name&gt;springSecurityFilterChain&lt;/filter-name&gt;
          &lt;servlet-name&gt;HelloWorld&lt;/servlet-name&gt;
      &lt;/filter-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>Finally, my controller is:</strong></p>
  
  <pre><code>@Controller
  public class HomeController
  {
      @RequestMapping(value = "/hello", method = RequestMethod.GET)
      public String helloWorld(Model model)
      {
          return "pages/hello";
      }
  }
  </code></pre>
  
  <p>A screenshot of my project structure:</p>
  
  <p><img src="https://i.stack.imgur.com/wyhk1.png" alt="enter image description here"></p>