title: Spring Data REST with Spring MVC: Adding RepositoryRestMvcConfiguration to existing DispatcherServlet
body: <p>I have an existing Spring MVC Application with a DispatcherServlet and an XML based configuration.</p>
  
  <p>Now I would like to integrate Spring Data REST but I dont know how to do this in a clean way. I added </p>
  
  <pre><code>&lt;context:component-scan&gt;...&lt;/context:component-scan&gt;
  </code></pre>
  
  <p>so my RestControllers are found but I fail in adding a RepositoryRestMvcConfiguration config. I tried the annotation driven approach which doesnt work</p>
  
  <pre><code>@Configuration
  public class RestConfiguration extends RepositoryRestMvcConfiguration {
  ...
  }
  </code></pre>
  
  <p>and the</p>
  
  <pre><code>&lt;bean class="com.mypackage.rest.RestConfiguration" /&gt;
  </code></pre>
  
  <p>approach is not working either.</p>
  
  <p>I also tried the follwing in the web.xml</p>
  
  <pre><code>&lt;servlet&gt;
      &lt;servlet-name&gt;myservlet&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;contextClass&lt;/param-name&gt;
          &lt;param-value&gt;org.springframework.web.context.support.AnnotationConfigWebApplicationContext&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;init-param&gt;
        &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
        &lt;param-value&gt;com.mypackage.rest.RestConfiguration&lt;/param-value&gt;
      &lt;/init-param&gt;
      &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  </code></pre>
  
  <p>Strange thing is, a method annotated with @PostConstruct is called, but non of the configure* methods.</p>
  
  <p>In the <a href="http://docs.spring.io/spring-data/rest/docs/2.0.0.RC1/reference/html/install-chapter.html#d5e117" rel="nofollow">docs</a> for Spring Data REST is a chapter where it is explained how to add a Spring Data REST to a Spring MVC application in code. It also says </p>
  
  <blockquote>
    <p>The equivalent of the above in a standard web.xml will also work identically to this configuration if you are still in a servlet 2.5 environment. </p>
  </blockquote>
  
  <p>How do you do this?</p>