Spring Data MongoDB自定义存储库实现

时间:2015-12-25 01:24:45

标签: java spring mongodb spring-data autowired

我想用我的自定义实现替换Spring Data提供的SimpleMongoRepository实现。

public class BaseRepositoryImpl<T, ID extends Serializable> implements BaseRepository<T, ID> {
    private MongoOperations mongoOperations;
    private MongoEntityInformation<T, ID> entityInformation;
    @Autowired
    private Set<QueryFilter<T>> filters;
    @Autowired
    public BaseRepositoryImpl(
            Set<QueryFilter<T>> filters,
            MongoEntityInformation<T, ID> entityInformation,
            MongoOperations mongoOperations
    ) {
        this.mongoOperations = mongoOperations;
        this.entityInformation = entityInformation;
        this.filters = filters;
   }

    public BaseRepositoryImpl(
            MongoEntityInformation<T, ID> entityInformation,
            MongoOperations mongoOperations
   ) {
        this.mongoOperations = mongoOperations;
        this.entityInformation = entityInformation;
    }

    ...
}
配置中的

@EnableMongoRepositories(
    basePackages = {"com.mycomp.mymodule.repository"},
    repositoryBaseClass = com.mycomp.mymodule.repository.BaseRepositoryImpl.class
)
public abstract class MyModuleConfiguration extends AbstractMongoConfiguration {
...

我的目标是对所有存储库的查询应用一些过滤器。一切正常但是对于我的实现,我需要向我的实现类注入一个更多的参数。

我有实现QueryFilter的过滤器类,我希望将它加载到过滤器字段,但它不会发生......

0 个答案:

没有答案