Cosium / spring-data-jpa-entity-graph

Spring Data JPA extension allowing full dynamic usage of EntityGraph on repositories
MIT License
478 stars 49 forks source link

Bean repository could not be found #63

Closed smtrad closed 2 years ago

smtrad commented 2 years ago

With spring-boot-starter-parent= 2.5.4 , java version 11 and spring-data-jpa-entity-graph.version 2.5.0 (or <) a Bean Repository could not be found on application start.


APPLICATION FAILED TO START


Description:

Field userRepository in com.ead.authuser.service.impl.UserServiceImpl required a bean of type 'com.ead.authuser.repository.UserRepository' that could not be found.


@Configuration @EnableJpaRepositories(repositoryFactoryBeanClass = EntityGraphJpaRepositoryFactoryBean.class) public class JpaRepositoryConfig { }

`@Repository public interface UserRepository extends GenericRepository<User, UUID> {

boolean existsByLoginOrEmail(String login, String email);
User getByLoginOrEmail(String login, String email);

}`

public interface GenericRepository<MODEL extends AbstractEntity, MODEL_ID extends Serializable> extends //JpaRepository<MODEL, MODEL_ID>, JpaSpecificationExecutor<MODEL> EntityGraphJpaRepository<MODEL, MODEL_ID>, EntityGraphJpaSpecificationExecutor<MODEL> { }

Note that when I use "extends JpaRepository<MODEL, MODEL_ID>, JpaSpecificationExecutor" the application works fine.

thorstenhilker commented 2 years ago

You have to use the annotation "@EnableJpaRepositories" in your main class: @SpringBootApplication @EnableJpaRepositories(repositoryFactoryBeanClass = EntityGraphJpaRepositoryFactoryBean.class) public class Application { ...

Hope that helps.

reda-alaoui commented 2 years ago

Bug report template bypassed => issue closed.

NicoStrecker commented 1 year ago

If you prefer using a Configuration-File thats the way to go. @EnableJpaRepositories(repositoryFactoryBeanClass = EntityGraphJpaRepositoryFactoryBean.class,basePackageClasses = ProjectMainClass.class)

or if you rather want to specify the basePackage: @EnableJpaRepositories(repositoryFactoryBeanClass = EntityGraphJpaRepositoryFactoryBean.class,basePackages = "project.base.package")

@reda-alaoui you should update the doucmentation according to that information, to provide a smooth start for new users.