biliboc
biliboc

Reputation: 737

mongo: repositories no longer works

I'm having this configuration

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mongo="http://www.springframework.org/schema/data/mongo"
    xsi:schemaLocation="http://www.springframework.org/schema/context
      http://www.springframework.org/schema/context/spring-context.xsd
      http://www.springframework.org/schema/data/mongo
      http://www.springframework.org/schema/data/mongo/spring-mongo.xsd
      http://www.springframework.org/schema/beans
      http://www.springframework.org/schema/beans/spring-beans.xsd">

    <mongo:repositories base-package="com.x.record.persistence.repo"
        mongo-template-ref="mongoTemplate" />

    <context:component-scan base-package="com.x.record.persistence.impl" />

</beans>

where in the package com.x.record.persistence.impl I have a component that needs the repository from com.x.record.persistence.repo.

This is working for spring-data-mongodb version 1.5.2.RELEASE

If I upgrade to the any version greater than 1.6.0.RELEASE (I tried with 1.6.2 and 1.7.0) this no longer works. It is as if the mongo repository scan does not work and I get the error:

org.springframework.beans.factory.BeanCreationException:
Error creating bean with name 'noAuthRecordPersistenceService': Injection of autowired dependencies failed;
nested exception is org.springframework.beans.factory.BeanCreationException:
Could not autowire field: private com.x.record.persistence.repo.RecordRepository com.x.record.persistence.impl.NoAuthRecordPersistenceServiceImpl.repo;
nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException:
No qualifying bean of type [com.x.record.persistence.repo.RecordRepository] found for dependency:
expected at least 1 bean which qualifies as autowire candidate for this dependency.
Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Any ideas?

UPDATE: If I use MongoRepository instead of PagingAndSortingRepository it works:

THIS DOES NOT WORK (with 1.6.x and up): public interface RecordRepository extends PagingAndSortingRepository, RecordRepositoryCustom {

    Page<Record> findByOrgHierarchy( String orgId, Pageable pageable );

    Record findOneByIdAndOrgHierarchyIn( String id, Collection<String> orgIds );

    int countByGsRunId(String gsRunId);

}

THIS WORKS (with 1.6.x and up): public interface RecordRepository extends MongoRepository, RecordRepositoryCustom {

    Page<Record> findByOrgHierarchy( String orgId, Pageable pageable );

    Record findOneByIdAndOrgHierarchyIn( String id, Collection<String> orgIds );

    int countByGsRunId(String gsRunId);

}

The wirdest thing is that I have other repos that DO WORK with PagingAndSortingRepository

Upvotes: 8

Views: 584

Answers (1)

Raghuveer
Raghuveer

Reputation: 3057

Try sample here, if this works in latest version then its possible that some component of yours is still using a older version and an incompatible state might exists.

Paste your complete code so that community can test the issue.

Upvotes: 0

Related Questions