title: What could be causing RequestMappingHandlerMapping to not register correctly?
body: <p>I'm trying to register a <code>HandlerInterceptorAdapter</code> instance though no matter what I do it doesn't get executed.</p>
  
  <p>I've tried copying <a href="http://static.springsource.org/spring/docs/current/spring-framework-reference/html/mvc.html#mvc-handlermapping-interceptor">the example from the spring documentation</a> with no luck.</p>
  
  <p>Could it be that <code>&lt;annotation-driven&gt;</code> is doing something that could be preventing my interceptor from being registered?</p>
  
  <p>I tried removing the id from <code>handlerMapping</code> though that only caused spring to register two instances in the container.</p>
  
  <p>I've tried registering in both the root context and the servlet context.</p>
  
  <p><strong>Full servlet-context.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans:beans xmlns="http://www.springframework.org/schema/mvc"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:beans="http://www.springframework.org/schema/beans"
               xsi:schemaLocation="
                http://www.springframework.org/schema/mvc
                http://www.springframework.org/schema/mvc/spring-mvc-3.1.xsd
                http://www.springframework.org/schema/beans
                http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"&gt;
  
    &lt;!-- Configures the @Controller programming model --&gt;
    &lt;annotation-driven/&gt;
  
    &lt;beans:bean id="handlerMapping"
          class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"&gt;
      &lt;beans:property name="interceptors"&gt;
        &lt;beans:list&gt;
          &lt;beans:ref bean="officeHoursInterceptor"/&gt;
        &lt;/beans:list&gt;
      &lt;/beans:property&gt;
    &lt;/beans:bean&gt;
    &lt;beans:bean id="officeHoursInterceptor"
          class="com.johnsands.web.servlet.TimeBasedAccessInterceptor"&gt;
      &lt;beans:property name="openingTime" value="9"/&gt;
      &lt;beans:property name="closingTime" value="18"/&gt;
    &lt;/beans:bean&gt;
  
    &lt;!-- ReST Exception Handling
         http://www.stormpath.com/blog/spring-mvc-rest-exception-handling-best-practices-part-1
         --&gt;
    &lt;beans:bean id="restExceptionResolver"
                class="com.stormpath.spring.web.servlet.handler.RestExceptionHandler"&gt;
      &lt;beans:property name="order" value="100"/&gt;
      &lt;beans:property name="errorConverter"&gt;
        &lt;beans:bean class="com.johnsands.spring.web.servlet.handler.BasicRestErrorConverter"/&gt;
      &lt;/beans:property&gt;
      &lt;beans:property name="errorResolver"&gt;
        &lt;beans:bean class="com.stormpath.spring.web.servlet.handler.DefaultRestErrorResolver"&gt;
          &lt;beans:property name="localeResolver" ref="localeResolver"/&gt;
          &lt;beans:property name="defaultMoreInfoUrl" value="mailto:support@mycompany.com"/&gt;
          &lt;beans:property name="exceptionMappingDefinitions"&gt;
            &lt;beans:map&gt;
              &lt;!-- 404 --&gt;
              &lt;beans:entry key="com.johnsands.api.ResourceNotFoundException" value="404, _exmsg"/&gt;
  
              &lt;!-- 500 (catch all): --&gt;
              &lt;beans:entry key="Throwable" value="500"/&gt;
            &lt;/beans:map&gt;
          &lt;/beans:property&gt;
        &lt;/beans:bean&gt;
      &lt;/beans:property&gt;
    &lt;/beans:bean&gt;
  
    &lt;beans:bean id="localeResolver" class="org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver"/&gt;
  
    &lt;!-- Handles HTTP GET requests for /static/** by efficiently serving up static resources in the ${webappRoot}/static/ directory --&gt;
    &lt;resources mapping="/static/**" location="/static/" /&gt;
  
    &lt;!-- Resolves views selected for rendering by @Controllers to .jsp resources in the /WEB-INF/views directory --&gt;
    &lt;beans:bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;beans:property name="prefix" value="/WEB-INF/views/" /&gt;
      &lt;beans:property name="suffix" value=".jsp" /&gt;
    &lt;/beans:bean&gt;
  
    &lt;!-- Imports user-defined @Controller beans that process client requests --&gt;
    &lt;beans:import resource="controllers.xml" /&gt;
  
  &lt;/beans:beans&gt;
  </code></pre>
  
  <p>controllers.xml doesn't do much</p>
  
  <pre><code>&lt;!-- Maps '/' requests to the 'home' view --&gt;
  &lt;mvc:view-controller path="/" view-name="home"/&gt;
  &lt;mvc:view-controller path="/login" view-name="login" /&gt;
  &lt;mvc:view-controller path="/logout" view-name="logout" /&gt;
  
  &lt;!-- Scans the classpath of this application for @Components to deploy as beans --&gt;
  &lt;context:component-scan base-package="com.johnsands" /&gt;
  </code></pre>
  
  <p>Handler is as follows:</p>
  
  <pre><code>public class TimeBasedAccessInterceptor
          extends HandlerInterceptorAdapter {
  
      private static final Logger log =
              LoggerFactory.getLogger(TimeBasedAccessInterceptor.class);
      private int openingTime;
      private int closingTime;
  
      public TimeBasedAccessInterceptor() {
          log.info(" *** Constructing Instance *** ");
      }
  
      public void setOpeningTime(int openingTime) {
          this.openingTime = openingTime;
      }
  
      public void setClosingTime(int closingTime) {
          this.closingTime = closingTime;
      }
  
      @Override
      public boolean preHandle(HttpServletRequest request,
                               HttpServletResponse response,
                               Object handler) throws Exception {
          log.info(" *** (preHandle) *** ");
          Calendar cal = Calendar.getInstance();
          int hour = cal.get(Calendar.HOUR_OF_DAY);
          if (openingTime &lt;= hour &amp;&amp; hour &lt; closingTime) {
              return true;
          } else {
              response.sendRedirect("http://www.google.com.au");
              return false;
          }
      }
  
      @Override
      public void postHandle(HttpServletRequest request,
                             HttpServletResponse response,
                             Object handler,
                             ModelAndView modelAndView)
              throws Exception {
          log.info(" *** (postHandle) *** ");
      }
  
      @Override
      public void afterCompletion(HttpServletRequest request,
                                  HttpServletResponse response,
                                  Object handler,
                                  Exception ex)
              throws Exception {
          log.info(" *** (afterCompletion) *** ");
      }
  
  }
  </code></pre>