我只是想从参考文档正常工作.但是对于以下课程:
I am just trying to get the "Adding custom behaviour to all repositories" example from the reference doc working. But for the following class:
public class MyRepositoryImpl<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements MyRepository<T, ID> { public void sharedCustomMethod(ID id) { // implementation goes here } }我收到编译错误
找不到适合SimpleJpaRepository()的构造函数 构造函数org.springframework.data.jpa.repository.support.SimpleJpaRepository.SimpleJpaRepository(java.lang.Class,javax.persistence.EntityManager)不适用 (实际和正式参数列表的长度不同) 构造函数org.springframework.data.jpa.repository.support.SimpleJpaRepository.SimpleJpaRepository(org.springframework.data.jpa.repository.support.JpaEntityInformation,javax.persistence.EntityManager)不适用 (实际和正式论点列表的长度不同)
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)
我该如何工作?
推荐答案我并不咸,但是不幸的是,实现起来并不十分清楚.
I'm not salty but implementing this is unfortunately not clear at all.
查看图像以获取完整的示例github: github/mpereira-dev/spring- data-mongo-shared-repo-example
Look at the image for a complete example, github: github/mpereira-dev/spring-data-mongo-shared-repo-example
要点:
构造函数的参数0 com.example.demo.repository.ImplementationRepoNameDoesntMatterEitherUnlikeAddingCustomMethodsToSingleRepo 需要一个类型的bean 'org.springframework.data.mongodb.repository.query.MongoEntityInformation' 找不到.
Parameter 0 of constructor in com.example.demo.repository.ImplementationRepoNameDoesntMatterEitherUnlikeAddingCustomMethodsToSingleRepo required a bean of type 'org.springframework.data.mongodb.repository.query.MongoEntityInformation' that could not be found.
@EnableMongoRepositories( repositoryBaseClass = ImplementationRepoNameDoesntMatterEitherUnlikeAddingCustomMethodsToSingleRepo.class)
@EnableMongoRepositories( repositoryBaseClass = ImplementationRepoNameDoesntMatterEitherUnlikeAddingCustomMethodsToSingleRepo.class)
如果不告诉spring有关您的基类的信息,则会出现此错误(spring尝试将方法解析为查询):
to tell spring about your base class if you don't you will get this error (spring tries to parse the method into a query):
起因: org.springframework.data.mapping.PropertyReferenceException:否 找到类型为Person的属性someMethod!
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property someMethod found for type Person!
7.6.2.向所有存储库添加自定义行为
7.6.2. Adding custom behavior to all repositories
docs.spring.io/spring-data/mongodb/docs/current/reference/html/#repositories.custom-behaviour-for-all-repositories
更多推荐
Spring数据MongoDB示例不起作用
发布评论