title: "The requested resource is not available" when deploying Spring MVC webapp to JBoss
body: <p>I am starting a web application with Spring MVC deploying to a JBoss 6.4 server but I get the following whenevery I try to open the main page:</p>
  
  <pre><code>JBWEB000065: HTTP Status 404 - /iph/
  
  JBWEB000309: type JBWEB000067: Status report
  JBWEB000068: message /iph/
  JBWEB000069: description JBWEB000124: The requested resource is not available.
  
  JBoss Web/7.5.7.Final-redhat-1
  </code></pre>
  
  <p>This is the first time I'm using Maven and annotation-driven configuration, I have been reading very similar cases on StackOverflow but I can't figure out where the problem is.</p>
  
  <p>This is my pom.xml:</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/maven-v4_0_0.xsd"&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
    &lt;groupId&gt;mx.com.companyname.iph&lt;/groupId&gt;
    &lt;artifactId&gt;iph&lt;/artifactId&gt;
    &lt;packaging&gt;war&lt;/packaging&gt;
    &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
    &lt;name&gt;iph&lt;/name&gt;
    &lt;url&gt;http://maven.apache.org&lt;/url&gt;
  
    &lt;properties&gt;
        &lt;maven.compiler.source&gt;1.7&lt;/maven.compiler.source&gt;
        &lt;maven.compiler.target&gt;1.7&lt;/maven.compiler.target&gt;
        &lt;springframework.version&gt;4.3.13.RELEASE&lt;/springframework.version&gt;
        &lt;hibernate.version&gt;4.3.6.Final&lt;/hibernate.version&gt;
    &lt;/properties&gt;
  
    &lt;dependencies&gt;
      &lt;!-- JUnit --&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;!-- PostgreSQL --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.postgresql&lt;/groupId&gt;
          &lt;artifactId&gt;postgresql&lt;/artifactId&gt;
          &lt;version&gt;42.1.4.jre7&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Java Servlet --&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.1.0&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet.jsp&lt;/groupId&gt;
          &lt;artifactId&gt;javax.servlet.jsp-api&lt;/artifactId&gt;
          &lt;version&gt;2.3.1&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;javax.servlet&lt;/groupId&gt;
          &lt;artifactId&gt;jstl&lt;/artifactId&gt;
          &lt;version&gt;1.2&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Spring --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-core&lt;/artifactId&gt;
          &lt;version&gt;${springframework.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-web&lt;/artifactId&gt;
          &lt;version&gt;${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;${springframework.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.springframework&lt;/groupId&gt;
          &lt;artifactId&gt;spring-tx&lt;/artifactId&gt;
          &lt;version&gt;${springframework.version}&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;${springframework.version}&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;!-- Hibernate ORM &amp; Validator --&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;version&gt;${hibernate.version}&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
          &lt;version&gt;5.4.2.Final&lt;/version&gt;
      &lt;/dependency&gt;
  
    &lt;/dependencies&gt;
    &lt;build&gt;
      &lt;pluginManagement&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;3.2&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&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.4&lt;/version&gt;
                  &lt;configuration&gt;
                      &lt;warSourceDirectory&gt;src/main/webapp&lt;/warSourceDirectory&gt;
                      &lt;warName&gt;iph&lt;/warName&gt;
                      &lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/pluginManagement&gt;
      &lt;finalName&gt;iph&lt;/finalName&gt;
    &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>This is my AppConfig class:</p>
  
  <pre><code>package mx.com.companyname.iph.configuration;
  
  import org.springframework.context.annotation.Bean;
  import org.springframework.context.annotation.ComponentScan;
  import org.springframework.context.annotation.Configuration;
  import org.springframework.web.servlet.ViewResolver;
  import org.springframework.web.servlet.config.annotation.EnableWebMvc;
  import org.springframework.web.servlet.view.InternalResourceViewResolver;
  import org.springframework.web.servlet.view.JstlView;
  
  @Configuration
  @EnableWebMvc
  @ComponentScan(basePackages = "mx.com.companyname.iph")
  public class AppConfig {
  
      @Bean
      public ViewResolver viewResolver() {
          InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
  
          viewResolver.setViewClass(JstlView.class);
          viewResolver.setPrefix("/WEB-INF/view/");
          viewResolver.setSuffix(".jsp");
  
          return viewResolver;
      }
  
  }
  </code></pre>
  
  <p>This is my AppInitializer class:</p>
  
  <pre><code>package mx.com.companyname.iph.configuration;
  
  import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;
  
  public class AppInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
  
      @Override
      protected Class&lt;?&gt;[] getRootConfigClasses() {
          return new Class[] { AppConfig.class };
      }
  
      @Override
      protected Class&lt;?&gt;[] getServletConfigClasses() {
          return null;
      }
  
      @Override
      protected String[] getServletMappings() {
          return new String[] {"/"};
      }
  
  }
  </code></pre>
  
  <p>And this is the code of my Controller class:</p>
  
  <pre><code>package mx.com.companyname.iph.controller;
  
  import javax.servlet.http.HttpServletRequest;
  
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.RequestMapping;
  
  @Controller
  @RequestMapping("/")
  public class MainController {
  
      @RequestMapping("/")
      public String main(HttpServletRequest request, Model model) {
          return "index";
      }
  
  }
  </code></pre>
  
  <p>My JSP view file is located on <strong>src/main/webapp/WEB-INF/view/index.jsp</strong>:</p>
  
  <pre><code>&lt;%@ page language="java" contentType="text/html; UTF-8"
      pageEncoding="UTF-8"%&gt;
  &lt;%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;h2&gt;Hello world!&lt;/h2&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The console log shows no errors. Even the first line on the following block appears to be mapping correctly the <strong>"/"</strong> route to the main method of my Controller:</p>
  
  <pre><code>17:15:18,748 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] (ServerService Thread Pool -- 51) Mapped "{[/]}" onto public java.lang.String mx.com.companyname.iph.controller.MainController.main(javax.servlet.http.HttpServletRequest,org.springframework.ui.Model)
  17:15:18,803 INFO  [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter] (ServerService Thread Pool -- 51) Looking for @ControllerAdvice: Root WebApplicationContext: startup date [Thu Dec 28 17:15:17 CST 2017]; root of context hierarchy
  17:15:18,920 INFO  [org.springframework.web.context.ContextLoader] (ServerService Thread Pool -- 51) Root WebApplicationContext: initialization completed in 1339 ms
  17:15:18,921 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/iph]] (ServerService Thread Pool -- 51) Initializing Spring FrameworkServlet 'dispatcher'
  17:15:18,921 INFO  [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 51) FrameworkServlet 'dispatcher': initialization started
  17:15:18,923 INFO  [org.springframework.web.context.support.AnnotationConfigWebApplicationContext] (ServerService Thread Pool -- 51) Refreshing WebApplicationContext for namespace 'dispatcher-servlet': startup date [Thu Dec 28 17:15:18 CST 2017]; parent: Root WebApplicationContext
  17:15:18,924 INFO  [org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor] (ServerService Thread Pool -- 51) JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
  17:15:18,950 INFO  [org.springframework.web.servlet.DispatcherServlet] (ServerService Thread Pool -- 51) FrameworkServlet 'dispatcher': initialization completed in 29 ms
  17:15:19,006 INFO  [org.jboss.as.server] (ServerService Thread Pool -- 28) JBAS015859: Implementado "iph.war" (runtime-name : "iph.war")
  17:15:19,011 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015961: Interfaz de administración http escuchando en http://127.0.0.1:9990/management
  17:15:19,012 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015951: Consola de administración escuchando en http://127.0.0.1:9990
  17:15:19,012 INFO  [org.jboss.as] (Controller Boot Thread) JBAS015874: JBoss EAP 6.4.0.GA (AS 7.5.0.Final-redhat-21) inició en 5133ms - Inició 617 de 655 servicios (63 servicios son perezosos, pasivos o por demanda)
  </code></pre>
  
  <p>The main method of the Controller is not being executed. According to another similar cases and the Spring reference, I also tried to switch the Servlet Mapping route in the AppInitializer class as follows:</p>
  
  <pre><code>@Override
  protected String[] getServletMappings() {
      return new String[] {"/*"};
  }
  </code></pre>
  
  <p>And Spring successfully sends the request to the main method of the Controller, however the 404 error persists and there's another error on the console:</p>
  
  <pre><code>17:20:23,997 WARN  [org.springframework.web.servlet.PageNotFound] (http-localhost/127.0.0.1:8080-2) No mapping found for HTTP request with URI [/iph/WEB-INF/view/index.jsp] in DispatcherServlet with name 'dispatcher'
  </code></pre>
  
  <p>Can someone help me to find out what's wrong with my code? Thank you.</p>