gpt4 book ai didi

Spring 数据 MongoDB 示例不起作用

转载 作者:可可西里 更新时间:2023-11-01 09:56:18 24 4
gpt4 key购买 nike

我只是想从 reference doc 中获取“向所有存储库添加自定义行为”示例在职的。但是对于下面的类:

public class MyRepositoryImpl<T, ID extends Serializable>
extends SimpleJpaRepository<T, ID> implements MyRepository<T, ID> {

public void sharedCustomMethod(ID id) {
// implementation goes here
}
}

编译错误

no suitable constructor found for SimpleJpaRepository()
constructor org.springframework.data.jpa.repository.support.SimpleJpaRepository.SimpleJpaRepository(java.lang.Class,javax.persistence.EntityManager) is not applicable
(actual and formal argument lists differ in length)
constructor org.springframework.data.jpa.repository.support.SimpleJpaRepository.SimpleJpaRepository(org.springframework.data.jpa.repository.support.JpaEntityInformation,javax.persistence.EntityManager) is not applicable
(actual and formal argument lists differ in length)

我怎样才能让它工作?

最佳答案

使用 spring-data mongodb 的“向所有存储库添加自定义行为”的适当解决方案在 post 中有详细说明。 .

按照上面帖子中描述的步骤进行操作后,您可以使用任何存储库接口(interface)来扩展 custom-shared-repository-interface,如下所示

@Repository
public interface CustomerRepository extends MongoRepository<Customer, String>,
WootideRepositoryCustom<Customer, String> {
}

WootideRepositoryImpl 中提供的实现将在 CustomerRepository 中可用。

这对我来说效果很好。

希望更新 spring data mongodb 文档,因为它是第一个引用位置。

关于Spring 数据 MongoDB 示例不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9842481/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com