title: Spring Data REST custom query integration
body: <p>I want to create a REST link for an <code>Employee</code> entity that will basically be a <code>findByAllFields</code> query. Of course this should be combined with <code>Page</code> and <code>Sort</code>. In order to do that I have implemented the following code:</p>
  
  <pre><code>@Entity
  public class Employee extends Persistable&lt;Long&gt; {
  
      @Column
      private String firstName;
  
      @Column
      private String lastName;
  
      @Column
      private String age;
  
      @Column
      @Temporal(TemporalType.TIMESTAMP)
      private Date hiringDate;
  }
  </code></pre>
  
  <p>So I would like to have lets say a query where I can do:</p>
  
  <pre><code>http://localhost:8080/myApp/employees/search/all?firstName=me&amp;lastName=self&amp;ageFrom=20&amp;ageTo=30&amp;hiringDateFrom=12234433235
  </code></pre>
  
  <p>So I have the following <code>Repository</code></p>
  
  <pre><code> @RepositoryRestResource(collectionResourceRel="employees", path="employees")
   public interface EmployeeRepository extends PagingAndSortingRepository&lt;Employee, Long&gt;, 
                                                           JpaSpecificationExecutor&lt;Employee&gt; {
  
   }
  </code></pre>
  
  <p>Ok so now I need a RestController</p>
  
  <pre><code>@RepositoryRestController
  public class EmployeeSearchController {
  
      @Autowired
      private EmployeeRepository employeRepository;
  
      @RequestMapping(value = "/employees/search/all/search/all", method = RequestMethod.GET)
      public Page&lt;Employee&gt; getEmployees(EmployeeCriteria filterCriteria, Pageable pageable) {
  
          //EmployeeSpecification uses CriteriaAPI to form dynamic query with the fields from filterCriteria
          Specification&lt;Employee&gt; specification = new EmployeeSpecification(filterCriteria);
  
          return employeeRepository.findAll(specification, pageable);
  }
  </code></pre>
  
  <p>Ok, obviously this does its job but <strong>it is not integrated with HATEOAS</strong>.
  I have attempted to assemble a resource changing the controller to this:</p>
  
  <pre><code>public PagedResources&lt;Resource&lt;Employee&gt;&gt; getEmployees(
                  PagedResourcesAssembler&lt;Employee&gt; assembler,
                  EmployeeCriteria filterCriteria, Pageable pageable) {
  
          //EmployeeSpecification uses CriteriaAPI to form dynamic query with the fields from filterCriteria
          Specification&lt;Employee&gt; specification = new EmployeeSpecification(filterCriteria);
  
          Page&lt;Employee&gt; employees = employeeRepository.findAll(specification, pageable);
          return assembler.toResource(employees);
  }
  </code></pre>
  
  <p>Obviously I'm missing something from the above since it doesnt work and I'm getting the following Exception:</p>
  
  <pre><code>Could not instantiate bean class [org.springframework.data.web.PagedResourcesAssembler]: No default constructor found;
  </code></pre>
  
  <p>Ok so to make the question clear <strong>I am trying to integrate the above resource into the rest of the HATEOAS architecture.</strong> I'm not entirely sure if this is the correct approach so any other suggestions are welcome.</p>
  
  <p>EDIT: 
  Here you can see a similar implementation. Please take a look at the configuration, you will see that all but one of the "Person" controllers are working.
  <a href="https://github.com/cgeo7/spring-rest-example">https://github.com/cgeo7/spring-rest-example</a></p>