I'm trying to implement a custom Spring repository. I have the interface:
public interface FilterRepositoryCustom {
List<User> filterBy(String role);
}
the implementation:
public class FilterRepositoryImpl implements FilterRepositoryCustom {
...
}
and the "main" repository, extending my custom repository:
public interface UserRepository extends JpaRepository<User, String>, FilterRepositoryCustom {
...
}
I'm using Spring Boot and, according to the docs:
By default, Spring Boot will enable JPA repository support and look in
the package (and its subpackages) where @SpringBootApplication is
located.
When I run my application, I get this error:
org.springframework.data.mapping.PropertyReferenceException: No property filterBy found for type User!
Best Answer
The problem here is that you are creating
FilterRepositoryImpl
but you are using it inUserRepository
. You need to createUserRepositoryImpl
to make this work.Read this doc for more detail
Basically
Spring Data 2.x update
This answer was written for Spring 1.x. As Matt Forsythe pointed out, the naming expectations changed with Spring Data 2.0. The implementation changed from
the-final-repository-interface-name-with-an-additional-Impl-suffix
tothe-custom-interface-name-with-an-additional-Impl-suffix
.So in this case, the name of the implementation would be:
UserRepositoryCustomImpl
.