springrepositoryspring-dataspring-data-jpa

Can I choose the name of my jpa repository?


I have to name my interface that extends the CrudRepository with a spacific name (I use spring and Jpa) i.e.

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

so in this case I have a Entity with name UserRepository

I tried annotation

@Entity(name="UserCustomRepository")
public interface UserRepository extends CrudRepository<User, Long> {}

but it doesn't work...


Solution

  • Apparently it's not possible according to the documentation, see 1.3.3.1. XML Configuration:

    Each of these beans will be registered under a bean name that is derived from the interface name, so an interface of UserRepository would be registered under userRepository.

    Why do you need a custom name? Besides your example with @Entity(name="UserCustomRepository") is completely broken, @Entity is used to mark JPA entities, not Spring beans/repositories.