title: How to set servlet path for every request through MockMvc
body: <p>Is it possible to set the servlet path for all requests (get, post, put, delete) which go through the MockMvc?</p>
  
  <p>The Spring dispatch servlet is mapped to /rest/*
  But in my test I have to remove the /rest part in the url otherwise Spring test does not recognise the controller.</p>
  
  <p>EDIT</p>
  
  <p>@Sotirios:</p>
  
  <p>Something is possible like:</p>
  
  <pre><code>public class MyWebTests {
  
      private MockMvc mockMvc;
  
      @Before
      public void setup() {
          mockMvc = standaloneSetup(new AccountController())
              .defaultRequest(get("/")
              .contextPath("/app").servletPath("/main")
              .accept(MediaType.APPLICATION_JSON).build();
  </code></pre>
  
  <p>}
  }</p>
  
  <p>But I wonder how servlet path can be set for all requests. Above code is from <a href="http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/testing.html" rel="noreferrer">http://docs.spring.io/spring/docs/3.2.x/spring-framework-reference/html/testing.html</a>.</p>
  
  <p>Or is it only possible to define the servletPath with the standaloneSetup?</p>