Cosium / spring-data-jpa-entity-graph

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

Cannot Bind EntityGraphRepositry #17

Closed vladamx closed 6 years ago

vladamx commented 6 years ago

Hi,

Idea of the library is awesome, but i can't make it to work. I am building SpringBoot Application and I have followed steps for integration from 2.0.0 documentation page. Spring throws errors on initialization. Repository bean is not defined.

Code

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

@Repository public interface PurchaseOrderRepository extends EntityGraphJpaRepository<PurchaseOrderEntity, Long> { PurchaseOrderEntity findFirstByOrderByCreatedAtDesc(); PurchaseOrderEntity findFirstByOrderByCreatedAtAsc(); }

@Autowired public PurchaseOrderService(PurchaseOrderRepository purchaseOrderRepository, UserOrderAssignmentRepository userOrderAssignmentRepository, PurchaseOrderMapper purchaseOrderMapper) { this.userOrderAssignmentRepository = userOrderAssignmentRepository; this.purchaseOrderMapper = purchaseOrderMapper; this.purchaseOrderRepository = purchaseOrderRepository; }

Error

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled. 2018-03-21 22:36:44.608 ERROR 18380 --- [ restartedMain] o.s.b.d.LoggingFailureAnalysisReporter :


APPLICATION FAILED TO START


Description:

Parameter 0 of constructor in api.service.PurchaseOrderService required a bean of type 'api.repo.PurchaseOrderRepository' that could not be found.

Action:

Consider defining a bean of type 'api.repo.PurchaseOrderRepository' in your configuration.

Process finished with exit code 0

reda-alaoui commented 6 years ago

Are you sure that repository interface scanning is enabled and that your repository is in a scanned package? Can you provide a git repository allowing to reproduce the issue?

vladamx commented 6 years ago

When using plain JPARepository everything works as expected. Unfortunately I can't, because project is internal. I am thinking how to provide more context to you...

reda-alaoui commented 6 years ago

@vladamx , did you solve the issue? Did you find a way to give me more context?

vladamx commented 6 years ago

Hey. Thanks for asking! Currently, I don't have time to deal with it. Maybe I will reopen the issue in the future. Sorry for the inconvenience.

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")

Or you add this annotation to your main class.

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