title: The required resource is not available using Spring
body: <p>I have a problem with using Spring. My problem is an 404 error and in the error message appear:</p>
  <blockquote>
  <p>The required resource is not available</p>
  </blockquote>
  <p>How can I solve this?</p>
  <p>My web.xml</p>
  <pre><code> &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  
  &lt;web-app version=&quot;2.5&quot; xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;&gt;
  
    &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/spring/applicationContext.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;display-name&gt;Springapp&lt;/display-name&gt;
    
    &lt;servlet&gt;
      &lt;servlet-name&gt;springapp&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;
              /WEB-INF/spring/app-config.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;dispatcher&lt;/servlet-name&gt;  
         &lt;url-pattern&gt;*.htm&lt;/url-pattern&gt;  
  &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  <p>My pom.xml</p>
  <pre><code>    &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/maven-v4_0_0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;com.conexiona&lt;/groupId&gt;
    &lt;artifactId&gt;springapp&lt;/artifactId&gt;
    &lt;packaging&gt;war&lt;/packaging&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;name&gt;springapp Maven Webapp&lt;/name&gt;
    &lt;url&gt;http://maven.apache.org&lt;/url&gt;
    &lt;dependencies&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.mongodb&lt;/groupId&gt;
          &lt;artifactId&gt;mongo-java-driver&lt;/artifactId&gt;
          &lt;version&gt;3.4.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
        &lt;groupId&gt;junit&lt;/groupId&gt;
        &lt;artifactId&gt;junit&lt;/artifactId&gt;
        &lt;version&gt;4.12&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-core&lt;/artifactId&gt;
          &lt;version&gt;${org.springframework.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;${org.springframework.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;servlet-api&lt;/artifactId&gt;
          &lt;version&gt;2.5&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet.jsp.jstl&lt;/groupId&gt;
          &lt;artifactId&gt;jstl-api&lt;/artifactId&gt;
          &lt;version&gt;1.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.apache.taglibs&lt;/groupId&gt;
          &lt;artifactId&gt;taglibs-standard-impl&lt;/artifactId&gt;
          &lt;version&gt;1.2.5&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.validation&lt;/groupId&gt;
          &lt;artifactId&gt;validation-api&lt;/artifactId&gt;
          &lt;version&gt;1.1.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate.ogm&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-ogm-mongodb&lt;/artifactId&gt;
          &lt;version&gt;4.1.0.Beta8&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-api&lt;/artifactId&gt;
          &lt;version&gt;1.7.21&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.slf4j&lt;/groupId&gt;
          &lt;artifactId&gt;slf4j-log4j12&lt;/artifactId&gt;
          &lt;version&gt;1.7.21&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
          &lt;version&gt;5.1.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-orm&lt;/artifactId&gt;
          &lt;version&gt;${org.springframework.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework.data&lt;/groupId&gt;
          &lt;artifactId&gt;spring-data-mongodb&lt;/artifactId&gt;
          &lt;version&gt;1.10.1.RELEASE&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.spec.javax.transaction&lt;/groupId&gt;
          &lt;artifactId&gt;jboss-transaction-api_1.1_spec&lt;/artifactId&gt;
          &lt;version&gt;1.0.0.Final&lt;/version&gt;
          &lt;scope&gt;provided&lt;/scope&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.jbossts&lt;/groupId&gt;
          &lt;artifactId&gt;jbossjta&lt;/artifactId&gt;
          &lt;version&gt;4.16.4.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;4.2.12.Final&lt;/version&gt;
      &lt;/dependency&gt;
    &lt;/dependencies&gt;
    &lt;build&gt;
      &lt;finalName&gt;springapp&lt;/finalName&gt;
    &lt;/build&gt;
    &lt;properties&gt;
      &lt;org.springframework.version&gt;4.3.7.RELEASE&lt;/org.springframework.version&gt;
    &lt;/properties&gt;
  &lt;/project&gt;
  </code></pre>
  <p>My hello.jsp</p>
  <pre><code>&lt;%@ include file=&quot;/WEB-INF/views/include.jsp&quot; %&gt;
  
  &lt;html&gt;
    &lt;head&gt;&lt;title&gt;&lt;fmt:message key=&quot;title&quot;/&gt;&lt;/title&gt;&lt;/head&gt;
    &lt;body&gt;
      &lt;h1&gt;&lt;fmt:message key=&quot;heading&quot;/&gt;&lt;/h1&gt;
      &lt;p&gt;&lt;fmt:message key=&quot;greeting&quot;/&gt; &lt;c:out value=&quot;${model.now}&quot;/&gt;&lt;/p&gt;
      &lt;h3&gt;Sensors&lt;/h3&gt;
      &lt;c:forEach items=&quot;${model.logs_19452055438107661658}&quot; var=&quot;sens&quot;&gt;
        &lt;c:out value=&quot;${sens.idsensor}&quot;/&gt; &lt;i&gt;$&lt;c:out value=&quot;${sens.temperature}&quot;/&gt;$&lt;c:out value=&quot;${sens.timestamp}&quot;/&gt;&lt;/i&gt;&lt;br&gt;&lt;br&gt;
      &lt;/c:forEach&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>My include.jsp</p>
  <pre><code>&lt;%@ page session=&quot;false&quot;%&gt;
  &lt;%@ taglib prefix=&quot;c&quot; uri=&quot;http://java.sun.com/jsp/jstl/core&quot; %&gt;
  &lt;%@ taglib prefix=&quot;fmt&quot; uri=&quot;http://java.sun.com/jsp/jstl/fmt&quot; %&gt;
  </code></pre>
  <p>My MongoSensorDao.java</p>
  <pre><code>package com.conexiona.springapp.repository;
  
  import java.net.UnknownHostException;
  import java.util.List;
  import javax.persistence.PersistenceContext;
  import org.springframework.stereotype.Repository;
  import org.springframework.transaction.annotation.Transactional;
  import javax.persistence.EntityManager;
  import com.conexiona.springapp.domain.Sensor;
  import com.mongodb.DB;
  import com.mongodb.DBCollection;
  import com.mongodb.DBCursor;
  import com.mongodb.MongoClient;
  import com.mongodb.MongoException;
  
  @Repository(value = &quot;sensorDao&quot;)
  public class MongoSensorDao implements SensorDao
  {   
      EntityManager em;
      
      public static void main(String[] args)
      {
          try {
              MongoClient mongo = new MongoClient(&quot;172.16.1.25&quot;, 27017);
              
              DB db = mongo.getDB(&quot;kaa&quot;);
              DBCollection table = db.getCollection(&quot;logs_19452055438107661658&quot;);
              DBCursor document = table.find();
              
              try {
                  while (document.hasNext())
                      System.out.println(document.next());
              } finally {
                  document.close();
              }
              
          } catch (MongoException e) {
              e.printStackTrace();
          }
      }
  
      @Transactional(readOnly = true)
      @SuppressWarnings(&quot;unchecked&quot;)
      public List&lt;Sensor&gt; getSensorList() {
          return em.createQuery(&quot;select p from Sensor p order by p.idsensor&quot;).getResultList();
      }
  
      @Transactional(readOnly = false)
      public void saveSensor(Sensor sens) {
          em.merge(sens);
      }
  
  }
  </code></pre>
  <p>My app-config.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xmlns:mvc=&quot;http://www.springframework.org/schema/mvc&quot;
      xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
      xsi:schemaLocation=&quot;http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd&quot;&gt;
   
      &lt;bean id=&quot;messageSource&quot; class=&quot;org.springframework.context.support.ResourceBundleMessageSource&quot;&gt;
          &lt;property name=&quot;basename&quot; value=&quot;messages&quot;/&gt;
      &lt;/bean&gt;
  
      &lt;!-- Scans the classpath of this application for @Components to deploy as beans --&gt;
      &lt;context:component-scan base-package=&quot;com.conexiona.springapp.web&quot; /&gt;
  
      &lt;!-- Configures the @Controller programming model --&gt;
      &lt;mvc:annotation-driven/&gt;
      
      &lt;bean id=&quot;viewResolver&quot; class=&quot;org.springframework.web.servlet.view.InternalResourceViewResolver&quot;&gt;
          &lt;property name=&quot;viewClass&quot; value=&quot;org.springframework.web.servlet.view.JstlView&quot;&gt;&lt;/property&gt;
          &lt;property name=&quot;prefix&quot; value=&quot;/WEB-INF/views/&quot;&gt;&lt;/property&gt;
          &lt;property name=&quot;suffix&quot; value=&quot;.jsp&quot;&gt;&lt;/property&gt;        
      &lt;/bean&gt;
      &lt;mvc:annotation-driven/&gt;
  &lt;/beans&gt;
  </code></pre>
  <p>And my applicationContext.xml</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;
      xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
      xmlns:context=&quot;http://www.springframework.org/schema/context&quot;
      xmlns:p=&quot;http://www.springframework.org/schema/p&quot;
      xmlns:tx=&quot;http://www.springframework.org/schema/tx&quot;
      xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/tx
          http://www.springframework.org/schema/tx/spring-tx-4.2.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-4.2.xsd
          
          http://www.springframework.org/schema/data/mongo
          http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
          http://www.springframework.org/schema/jdbc
          http://www.springframework.org/schema/jdbc/spring-jdbc-3.0.xsd
          http://www.springframework.org/schema/beans
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd&quot;&gt;
   
      &lt;!-- holding properties for database connectivity /--&gt;
      &lt;context:property-placeholder location=&quot;classpath:jdbc.properties&quot;/&gt;
  
      &lt;!-- enabling annotation driven configuration /--&gt;
      &lt;context:annotation-config/&gt;
  
      &lt;bean id=&quot;dataSource&quot; class=&quot;org.springframework.jdbc.datasource.DriverManagerDataSource&quot;&gt;
        &lt;property name=&quot;driverClassName&quot; value=&quot;${jdbc.driverClassName}&quot;/&gt;
        &lt;property name=&quot;url&quot; value=&quot;${jdbc.url}&quot;/&gt;
        &lt;property name=&quot;username&quot;  value=&quot;${jdbc.username}&quot;/&gt;
        &lt;property name=&quot;password&quot; value=&quot;${jdbc.password}&quot;/&gt;
      &lt;/bean&gt;
  
      &lt;tx:annotation-driven transaction-manager=&quot;transactionManager&quot;/&gt;
  
      &lt;!-- Scans the classpath of this application for @Components to deploy as beans --&gt;
      &lt;context:component-scan base-package=&quot;com.conexiona.springapp.repository&quot; /&gt;
      &lt;context:component-scan base-package=&quot;com.conexiona.springapp.service&quot; /&gt;
      
  
  &lt;/beans&gt;
  </code></pre>
  <p>My controller</p>
  <pre><code>package com.conexiona.springapp.web;
  
  import java.io.IOException;
  import java.util.Date;
  import java.util.HashMap;
  import java.util.Map;
  
  import javax.servlet.ServletException;
  import javax.servlet.http.HttpServletRequest;
  import javax.servlet.http.HttpServletResponse;
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.servlet.ModelAndView;
  
  import com.conexiona.springapp.service.SensorManager;
  
  @Controller
  public class SensorController {
  
      protected final Log logger = LogFactory.getLog(getClass());
  
      @Autowired
      private SensorManager sensorManager;
  
      @RequestMapping(value=&quot;/hello.htm&quot;)
      public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
              throws ServletException, IOException {
  
          String now = (new Date()).toString();
          logger.info(&quot;Returning hello view with &quot; + now);
  
          Map&lt;String, Object&gt; myModel = new HashMap&lt;String, Object&gt;();
          myModel.put(&quot;now&quot;, now);
          myModel.put(&quot;sensors&quot;, this.sensorManager.getSensors());
  
          return new ModelAndView(&quot;hello&quot;, &quot;model&quot;, myModel);
      }
  
  
      public void setSensorManager(SensorManager sensorManager) {
          this.sensorManager = sensorManager;
      }
  }
  </code></pre>
  <p>I am trying to connect to a MongoDB database but I only obtain 404 error.</p>
  <p>Here is my project structure: <a href="https://i.stack.imgur.com/lAYrP.png" rel="nofollow noreferrer">project structure</a></p>