Adrian Ber
Adrian Ber

Reputation: 21370

Spring Data JPA Repositories

I have a repository definition like

public interface UserRepository extends CrudRepository<User, Long> {}

In the Spring context file I have

<jpa:repositories base-package="my.package"/>

Then I try to do something like

new Repositories(applicationContext).getRepositoryFor(User.class);

but I get the error

Method "getRepositoryFor" with signature "(Ljava/lang/Class;)Lorg/springframework/data/repository/CrudRepository;" is not applicable on this object

Does anyone have any idea what could have I done wrong?

Upvotes: 1

Views: 1716

Answers (2)

user41871
user41871

Reputation:

I have seen this issue. As Oliver notes, it is a version incompatibility between Spring Data JPA and Spring Data Commons.

One version of Repositories.getRepositoryFor() returns a CrudRepository and the other returns an Object, presumably to accommodate PagingAndSortingRepository to accommodate Repository. [Edited per Oliver's comment below.]

Upvotes: 2

Oliver Drotbohm
Oliver Drotbohm

Reputation: 83081

This feels more like a version incompatibility between the Spring Data JPA module and Spring Data Commons. Make sure you use the version of Spring Data Commons that is referred to from the pom.xml of the Spring Data JPA version you use. Or, even better: do not declare a dependency on Spring Data Commons at all.

Upvotes: 2

Related Questions