title: Customize endpoints with Spring Data REST
body: <p>I've a project with Spring Boot 1.5.7, Spring Data REST, Hibernate, Spring JPA, Swagger2.</p>
  
  <p>I've two beans like these:</p>
  
  <pre><code>    @Entity
  public class TicketBundle extends AbstractEntity {
      private static final long serialVersionUID = 404514926837058071L;
  
      @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      private List&lt;Note&gt; notes = new ArrayList&lt;&gt;();
  
      .....
      }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>    @Entity
  public class Note extends AbstractEntity {
      private static final long serialVersionUID = -5062313842902549565L;
  
      @Lob
      private String text;
      ...
      }
  </code></pre>
  
  <p>I'm exposing my methods via Repository:</p>
  
  <pre><code>@Transactional
  @RepositoryRestResource(excerptProjection = TicketBundleProjection.class)
  @PreAuthorize("isAuthenticated()")
  public interface TicketBundleRepository extends PagingAndSortingRepository&lt;TicketBundle, Long&gt; {
  ....
  }
  </code></pre>
  
  <p>so in swagger I see the endpoint in which I'm interested that is needed to load the collection of notes from a specific ticket bundle:</p>
  
  <p><a href="https://i.stack.imgur.com/EZBx0.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/EZBx0.png" alt="enter image description here"></a></p>
  
  <p>Now, I want to override the default <code>GET /api/v1/ticketBundles/{id}/notes</code> and replace that with my custom method I put in <code>TicketBundleRepository</code>:</p>
  
  <pre><code>@Transactional(readOnly = true)
  @RestResource(rel = "ticketBundleNotes", path = "/ticketBundles/{id}/notes")
  @RequestMapping(method = RequestMethod.GET, path = "/ticketBundles/{id}/notes")
  @Query("SELECT n FROM TicketBundle tb JOIN tb.notes n WHERE tb.id=:id ORDER BY n.createdDate DESC,n.id DESC")
  public Page&lt;Note&gt; getNotes(@Param("id") long id, Pageable pageable);
  </code></pre>
  
  <p>It's very convenient create the query in this way because I need to use Pageable and return a Page. Unfortunately I've two problems at this point.</p>
  
  <p><strong>First problem</strong>
  The method is mapped on the endpoint <code>/api/v1/ticketBundles/search/ticketBundles/{id}/notes</code> instad of <code>/api/v1/ticketBundles/ticketBundles/{id}/notes</code>
  <a href="https://i.stack.imgur.com/PsQso.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/PsQso.png" alt="enter image description here"></a></p>
  
  <p><strong>Second problem</strong>
  When I call the method from swagger I receive an HTTP 404:</p>
  
  <p>The request seems wrong. Seems the path variable is not understood:</p>
  
  <pre><code>curl -X GET --header 'Accept: application/json' 'http://localhost:8080/api/v1/ticketBundles/search/ticketBundles/{id}/notes?id=1'
  </code></pre>
  
  <p>This is the response from the server:</p>
  
  <pre><code>{
     "timestamp": "2017-10-05T14:00:35.563+0000",
     "status": 404,
     "error": "Not Found",
     "message": "No message available",
     "path": "/api/v1/ticketBundles/search/ticketBundles/%7Bid%7D/notes"
   }
  </code></pre>
  
  <p>without any error on the server side.</p>
  
  <p>Is there a way to override the endpoint <code>GET/api/v1/ticketBundles/{id}/notes</code> exposing it through <code>Repository</code> without using a custom controller (using that I would loose the facilities to manage the Pageable)?</p>
  
  <p>Furthermore, what am I doing wrong to get a HTTP 404 in the call I shown above?</p>