title: How to redirect redirect mock requests in Spring MVC REST test?
body: <p>In my web.xml I mapped the servlet to /api like this:</p>
  
  <pre><code>&lt;servlet-mapping&gt;
      &lt;servlet-name&gt;todo&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/api/*&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;servlet&gt;
      &lt;servlet-name&gt;todo&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  </code></pre>
  
  <p>So for the controller using <code>@RequestMapping(value = "/todo", method = RequestMethod.GET)</code>, it actually gets mapped to "/api/todo"</p>
  
  <p>But in test when I call <code>mockMvc.perform(get("/api/todo/"))</code> I got a 404. I have to call <code>get("/todo/")</code> to get the correct mapping in test. I hope to map the  controller in test like in actual scenario. Is that possible?</p>
  
  <p>I'm using <code>WebMvcConfigurerAdapter</code> in test and I tried</p>
  
  <pre><code>@Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
      registry.addResourceHandler("/api/**").addResourceLocations("/");
  }
  </code></pre>
  
  <p>but it didn't work.</p>