实现两者时,spring数据(基本存储库和单一存储库)中的自定义存储库不起作用

时间:2017-12-08 06:34:30

标签: spring spring-data

我们想要在所有存储库中使用一些常用方法(例如API level 26+(spring boot 2.0方法签名已更改),因此我们在基础存储库中添加此方法,并且我们还需要一些自定义方法特定于存储库,因此也实现了基础和自定义)

应用程序类:

fineOne

现在

    @EnableMongoRepositories(basePackages ={"com.kairos.activity.persistence.repository"},
    repositoryBaseClass = MongoBaseRepositoryImpl.class)
    public class KairosActivityApplication 


    @NoRepositoryBean
    public interface MongoBaseRepository<T, ID extends Serializable> extends MongoRepository<T, ID> {
         T findOne(ID id);
    }

    public class MongoBaseRepositoryImpl<T, ID extends Serializable>
    extends SimpleMongoRepository<T, ID> implements MongoBaseRepository<T, ID> {
        private final MongoOperations mongoOperations;
        private final MongoEntityInformation<T, ID> entityInformation;
        public MongoBaseRepositoryImpl(MongoEntityInformation<T, ID>  entityInformation,
                                  MongoOperations mongoOperations) {
            super(entityInformation, mongoOperations);
            // Keep the EntityManager around to used from the newly introduced methods.
            this.mongoOperations = mongoOperations;
            this.entityInformation=entityInformation;
        }
        @Override
        public T findOne(ID id) {
            Assert.notNull(id, "The given id must not be null!");

            return mongoOperations.findById(id, entityInformation.getJavaType(), entityInformation.getCollectionName());
        }
    }

存储库特定的自定义存储库不使用其方法对待主存储库的常规方法并给出解析错误

    @Repository
    public interface ActivityMongoRepository extends MongoBaseRepository<Activity, BigInteger>,CustomActivityMongoRepository {

        @Query(value="{staffId:?0,unitId:?3,disabled:false,startDate:{$gte:?1},endDate:{$lte:?2}}")
        List<ActivityQueryResult> findAllActivityBetweenDuration(Long staffIf, Date startDate, Date endDate,Long unitId);

        Long countByActivityTypeId(BigInteger activityTypeId);

    }

    public interface CustomActivityMongoRepository {

        void updatePhasesOfActivities(Long orgId, Date startDateInISO, Date endDateInISO, String phaseName, String PhaseDescription);
    }

应该有效,但我认为当我们实现基本自定义存储库(存储库特定的自定义实现被忽略)时

0 个答案:

没有答案
相关问题