title: Spring mvc autowire RequestMappingHandlerMapping
body: <p>I'm trying to autowire <code>org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping</code> in my spring mvc controller in order to get all url mappings and display them on UI, but not successfull. There is error that the bean is missing:</p>
  
  <pre><code> org.springframework.beans.factory.BeanCreationException: Could    not autowire field: org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping web.controller.WorkController.handlerMapping; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  </code></pre>
  
  <p>My web.xml:</p>
  
  <pre><code>&lt;display-name&gt;Spring MVC Application&lt;/display-name&gt;
  
  &lt;servlet&gt;
      &lt;servlet-name&gt;mvc-dispatcher&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/mvc-dispatcher-servlet.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;mvc-dispatcher&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  
  
  &lt;context-param&gt;
      &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
      &lt;param-value&gt;/WEB-INF/root-context.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;
  </code></pre>
  
  <p></p>
  
  <p>My mvc-dispatcher-servlet.xml:</p>
  
  <pre><code> &lt;context:annotation-config/&gt;
      &lt;context:component-scan base-package="web.controller"/&gt;
               &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
          &lt;property name="prefix"&gt;
              &lt;value&gt;/WEB-INF/views/&lt;/value&gt;
          &lt;/property&gt;
          &lt;property name="suffix"&gt;
              &lt;value&gt;.jsp&lt;/value&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p>My root-context.xml:</p>
  
  <pre><code>&lt;bean id="helloBean" class="web.beans.HelloBean"/&gt;
  </code></pre>
  
  <p>The java controller:
  </p>
  
  <pre><code>package web.controller;
  
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.context.ApplicationContext;
  import org.springframework.stereotype.Controller;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping;
  import web.beans.HelloBean;
  
  import java.util.List;
  
  @Controller
  public class WorkController {
  
      @Autowired RequestMappingHandlerMapping handlerMapping;
      @Autowired private HelloBean helloBean;
      @Autowired private ApplicationContext applicationContext;
  
      @RequestMapping(value = "/index")
      public String index() {
          return "index";
      }
  }
  </code></pre>