title: spring-data mongodb custom implementation PropertyReferenceException
body: <p>I'm trying to implement a custom query according to the Reference 4.4 Custom Implementations:</p>
  
  <p><a href="http://static.springsource.org/spring-data/data-mongodb/docs/current/reference/html/repositories.html" rel="nofollow noreferrer">http://static.springsource.org/spring-data/data-mongodb/docs/current/reference/html/repositories.html</a></p>
  
  <p><a href="https://stackoverflow.com/questions/17008947/spring-data-mongotemplate-vs-mongorepository">What&#39;s the difference between Spring Data&#39;s MongoTemplate and MongoRepository?</a></p>
  
  <p>I'm doing this because I need special queries using mongoTemplate.</p>
  
  <p>The error I'm getting is a PropertyReferenceException. So it seems that spring-data is trying to auto-generate the query which I don't want. I want to use my own custom query. </p>
  
  <pre><code>org.springframework.data.mapping.PropertyReferenceException: No property search found for type com.eerra.core.common.dto.User
  </code></pre>
  
  <p>The problem is described also here but the solution doesn't seem to work for me:</p>
  
  <p><a href="http://forum.springsource.org/showthread.php?114454-Custom-repository-functionality" rel="nofollow noreferrer">http://forum.springsource.org/showthread.php?114454-Custom-repository-functionality</a></p>
  
  <p><strong>Question</strong></p>
  
  <p>How can I implement my custom query interface and implementation without spring-data trying to auto-generate the query?</p>
  
  <p><strong>Configuration</strong></p>
  
  <p><strong><em>Spring Configuration</em></strong></p>
  
  <p><em>spring-data.xml</em></p>
  
  <pre><code>&lt;!-- Spring Data MongoDB repository support --&gt;
  &lt;mongo:repositories base-package="com.eerra.*.common.service" /&gt;
  </code></pre>
  
  <p>The Repository classes and interfaces are located in following package:</p>
  
  <p>com.eerra.core.common.service.UserRepositoryInterface.java
  com.eerra.core.common.service.UserRepoistoryCustom.java (interface)
  com.eerra.core.common.service.UserRepositoryCustomImpl.java (implementation)</p>
  
  <p><strong>UserRepositoryCustom.java</strong></p>
  
  <pre><code>public interface UserRepositoryCustom {
      List&lt;User&gt; searchAllUsers();
  }
  </code></pre>
  
  <p><strong>UserRepositoryCustomImpl.java</strong></p>
  
  <pre><code>public class UserRepositoryCustomImpl implements UserRepositoryCustom {
  
      @Autowired
      private MongoTemplate mongoTemplate;
  
      @Override
      public List&lt;User&gt; searchAllUsers() {
          return mongoTemplate.findAll(User.class);
      }
  }
  </code></pre>
  
  <p><strong>UserRepositoryInterface.java</strong></p>
  
  <pre><code>@Repository
  public interface UserRepositoryInterface extends MongoRepository&lt;User, String&gt;, UserRepositoryCustom {
      User findByEmail(String email);
      List&lt;User&gt; findByEmailLike(String email);
      List&lt;User&gt; findByEmailOrLastName(String email, String lastName);
      List&lt;User&gt; findByEmailOrFirstNameLike(String email, String firstName);
  
      @Query("{\"$or\" : [ { \"email\" : { \"$regex\" : ?0, \"$options\" : \"i\"}} , " +
          "{ \"firstName\" : { \"$regex\" : ?0, \"$options\" : \"i\"}}, " +
          "{ \"lastName\" : { \"$regex\" : ?0, \"$options\" : \"i\"}}]}")
      List&lt;User&gt; findByEmailOrFirstNameOrLastNameLike(String searchText);
  }
  </code></pre>