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

Error creating bean #26

Closed shastaxc closed 5 years ago

shastaxc commented 5 years ago

Hi, I'm trying to set up for the first time but am getting the following error: Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.cesicorp.magrathea.repository.UserRepository' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1506) at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1101) at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1062) at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:818) at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:724) ... 36 common frames omitted

Using spring-data-jpa version 2.0.9.RELEASE as seen here: [INFO] +- org.springframework.boot:spring-boot-loader-tools:jar:2.0.4.RELEASE:compile [INFO] | \- org.apache.commons:commons-compress:jar:1.14:compile [INFO] +- org.springframework.boot:spring-boot-starter-actuator:jar:2.0.4.RELEASE:compile [INFO] | \- io.micrometer:micrometer-core:jar:1.0.6:compile [INFO] | +- org.hdrhistogram:HdrHistogram:jar:2.1.10:compile [INFO] | \- org.latencyutils:LatencyUtils:jar:2.0.3:compile [INFO] +- org.springframework.boot:spring-boot-starter-aop:jar:2.0.4.RELEASE:compile [INFO] | \- org.aspectj:aspectjweaver:jar:1.8.13:compile [INFO] +- org.springframework.boot:spring-boot-starter-data-jpa:jar:2.0.4.RELEASE:compile [INFO] | +- org.springframework.boot:spring-boot-starter-jdbc:jar:2.0.4.RELEASE:compile [INFO] | | \- org.springframework:spring-jdbc:jar:5.0.8.RELEASE:compile [INFO] | +- javax.transaction:javax.transaction-api:jar:1.2:compile [INFO] | +- org.springframework.data:spring-data-jpa:jar:2.0.9.RELEASE:compile

And using spring-data-jpa-entity-graph version 2.0.7.

I applied @EnableJpaRepositories(repositoryFactoryBeanClass = EntityGraphJpaRepositoryFactoryBean.class)

And this is my UserRepository: ` @Repository public interface UserRepository extends EntityGraphJpaRepository<User, Long> {

String USERS_BY_LOGIN_CACHE = "usersByLogin";

String USERS_BY_EMAIL_CACHE = "usersByEmail";

Optional<User> findOneByActivationKey(String activationKey);

List<User> findAllByActivatedIsFalseAndCreatedDateBefore(Instant dateTime);

Optional<User> findOneByResetKey(String resetKey);

Optional<User> findOneByEmailIgnoreCase(String email);

Optional<User> findOneByLogin(String login);

Optional<User> findOneById(Long id);

Optional<User> findOneWithAuthoritiesById(Long id, EntityGraph entityGraph);

@Cacheable(cacheNames = USERS_BY_LOGIN_CACHE)
Optional<User> findOneWithAuthoritiesByLogin(String login, EntityGraph entityGraph);

@Cacheable(cacheNames = USERS_BY_EMAIL_CACHE)
Optional<User> findOneWithAuthoritiesByEmail(String email, EntityGraph entityGraph);

Page<User> findAllByLoginNot(Pageable pageable, String login);

} `

I would greatly appreciate any insight you might have.

shastaxc commented 5 years ago

I fixed this by changing to the following:

@EnableJpaRepositories( basePackages = {"com.cesicorp.magrathea.repository"}, repositoryFactoryBeanClass = EntityGraphJpaRepositoryFactoryBean.class )