title: Spring Data REST: Override repository method on the controller
body: <p>I have the following REST repository, whose implementation is generated at runtime by Spring.</p>
  
  <pre><code>@RepositoryRestResource
  public interface FooRepository extends CrudRepository&lt;Foo, Long&gt; {
  
  }
  </code></pre>
  
  <p>This means that I will have save(), find(), exists() and other methods available and exposed via REST.</p>
  
  <p>Now, I would like to override one of the methods; for example, save(). For that, I would create a controller exposing that method, like so:</p>
  
  <pre><code>@RepositoryRestController
  @RequestMapping("/foo")
  public class FooController {
  
      @Autowired
      FooService fooService;
  
  
      @RequestMapping(value = "/{fooId}", method = RequestMethod.PUT)
      public void updateFoo(@PathVariable Long fooId) {
          fooService.updateProperly(fooId);
      }
  
  }
  </code></pre>
  
  <p><strong>The problem:</strong>
  If I enable this controller, then all of the other methods implemented by Spring are not exposed anymore. So, for example, I can no longer do a GET request to /foo/1</p>
  
  <p><strong>Question:</strong>
  Is there a way of overriding REST methods while still keeping the other auto-generated Spring methods?</p>
  
  <p><strong>Extra info:</strong></p>
  
  <ol>
  <li><p>This question seems very similar:
  <a href="https://stackoverflow.com/questions/28455208/spring-data-rest-override-method-in-restcontroller-with-same-request-mapping-pa">Spring Data Rest: Override Method in RestController with same request-mapping-path</a> ... but I don't want to change the path to something like /foo/1/save</p></li>
  <li><p>I thought of using a @RepositoryEventHandler but I'm not very fond of that idea because I would like to encapsulate it under a service. Also, you seem to lose control of the transaction context.</p></li>
  <li><p><a href="http://docs.spring.io/spring-data/rest/docs/current/reference/html/#customizing-sdr.overriding-sdr-response-handlers" rel="noreferrer">This part of the Spring Data documentation</a> says the following:</p>
  
  <blockquote>
    <p>Sometimes you may want to write a custom handler for a specific
    resource. To take advantage of Spring Data REST’s settings, message
    converters, exception handling, and more, use the
    @RepositoryRestController annotation instead of a standard Spring MVC
    @Controller or @RestController</p>
  </blockquote></li>
  </ol>
  
  <p>so it seems that it should work out of the box, but unfortunately not.</p>