PropertyReferenceException:找不到类型的属性findAll

时间:2017-07-07 06:42:45

标签: spring-boot spring-data-jpa spring-data-elasticsearch

Spring boot Application

我的实体Test包含JpaRepositoryElasticSearchRepository 当我使用任何一个存储库时,它的工作正常。但是当为Test实体创建了两个存储库时,它会抛出错误bean创建错误。 No property findAll found for type Test!

@Data
@Table
@Entity
@Document(indexName = "test",type = "Test")
public class Test {

    @Id
    private Long id;
    @Field
    private String name;
}

public interface TestSearchRepository extends ElasticsearchRepository<Test,Long> {}

public interface FacilityRepository extends JpaRepository<Facility,Long> {}
*Error*:`eCaused by: org.springframework.data.mapping.PropertyReferenceException: No property findAll found for type Test!
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:85) ~[spring-data-commons-2.0.0.BUILD-20170705.074441-111.jar:na]
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309) ~[spring-data-commons-2.0.0.BUILD-20170705.074441-111.jar:na]
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:289) ~[spring-data-commons-2.0.0.BUILD-20170705.074441-111.jar:na]
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:248) ~[spring-data-commons-2.0.0.BUILD-20170705.074441-111.jar:na]
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:215) ~[spring-data-commons-2.0.0.BUILD-20170705.074441-111.jar:na]
    at org.springframework.data.repository.query.parser.Part.<init>(Part.java:81) ~[spring-data-commons-2.0.0.BUILD-20170705.074441-111.jar:na]
    at org.springframework.data.repository.query.parser.PartTree$OrPart.lambda$new$0(PartTree.java:239) ~[spring-data-commons-2.0.0.BUILD-20170705.074441-111.jar:na]
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_73]
    at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) ~[na:1.8.0_73]
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:1.8.0_73]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_73]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_73]
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_73]
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_73]
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_73]
    at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:240) ~[spring-data-commons-2.0.0.BUILD-20170705.074441-111.jar:na]
    at org.springframework.data.repository.query.parser.PartTree$Predicate.lambda$new$0(PartTree.java:368) ~[spring-data-commons-2.0.0.BUILD-20170705.074441-111.jar:na]
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_73]
    at java.util.Spliterators$ArraySpliterator.forEachRemaining(Spliterators.java:948) ~[na:1.8.0_73]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_73]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_73]
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_73]
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_73]
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_73]
    at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:369) ~[spring-data-commons-2.0.0.BUILD-20170705.074441-111.jar:na]
    at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:92) ~[spring-data-commons-2.0.0.BUILD-20170705.074441-111.jar:na]
    at org.springframework.data.elasticsearch.repository.query.ElasticsearchPartQuery.<init>(ElasticsearchPartQuery.java:46) ~[spring-data-elasticsearch-3.0.0.BUILD-20170705.074610-104.jar:na]
    at org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactory$ElasticsearchQueryLookupStrategy.resolveQuery(ElasticsearchRepositoryFactory.java:123) ~[spring-data-elasticsearch-3.0.0.BUILD-20170705.074610-104.jar:na]
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.lambda$null$0(RepositoryFactorySupport.java:491) ~[spring-data-commons-2.0.0.BUILD-20170705.074441-111.jar:na]
    at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[na:1.8.0_73]
    at java.util.Iterator.forEachRemaining(Iterator.java:116) ~[na:1.8.0_73]
    at java.util.Collections$UnmodifiableCollection$1.forEachRemaining(Collections.java:1049) ~[na:1.8.0_73]
    at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) ~[na:1.8.0_73]
    at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:481) ~[na:1.8.0_73]
    at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:471) ~[na:1.8.0_73]
    at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:708) ~[na:1.8.0_73]
    at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) ~[na:1.8.0_73]
    at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:499) ~[na:1.8.0_73]`

1 个答案:

答案 0 :(得分:0)

请尝试将JPA et elasticsearch存储库放在单独的程序包中,并使用以下显式配置以避免冲突:

@EnableJpaRepositories("my.jpa.repositories")
@EnableElasticsearchRepositories("my.search.repositories")