Spring 数据存储库扩展自定义存储库时出现 BeanCreationException

BeanCreationException when Spring Data Repository extends Custom Repository

我有以下存储库界面:

public interface FooRepository extends ReactiveMongoRepository<Foo, String>, CustomFooRepository {

}

以及以下自定义存储库界面:

public interface CustomFooRepository {

    Flux<Foo> findFooByFilters(FooSearchParams params);
}

实施如下:

@RequiredArgsConstructor
public class DefaultCustomFooRepository implements CustomFooRepository {

    private final ReactiveFluentMongoOperations fluentMongoOps;

    @Override
    public Flux<Foo> findFooByFilter(FooSearchParams params) {
        return fluentMongoOps
                .query(Foo.class)
                // using the received params to create a dynamic query
                .all();
    }
}

但是应用程序上下文失败并出现以下错误:

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'fooRepository' defined in com.foo.fooservice.foo.FooRepository defined in @EnableReactiveMongoRepositories declared on MongoReactiveRepositoriesRegistrar.EnableReactiveMongoRepositoriesConfiguration: Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property filter found for type Foo!

当我需要将自定义方法添加到 Spring 数据存储库时,我曾经严格遵循这种做法,但我从未遇到任何问题,我是做错了什么还是最近行为发生了变化?

找到问题了。

我的自定义存储库实现的名称是 DefaultCustomFooRepository

将其重命名为 CustomFooRepositoryImpl 修复了它。