Joh*_*Lim 10 spring-data spring-data-jpa spring-boot spring-data-elasticsearch
我试图在同一个域对象上使用Spring Data JPA和Spring Data Elasticsearch,但它不起作用.
当我尝试运行一个简单的测试时,我得到以下异常:
org.springframework.data.mapping.PropertyReferenceException:找不到Person类型的属性索引!org.springframework.data.mapping.PropertyPath.(PropertyPath.java:75)〜[spring-data-commons-1.11.0.RELEASE.jar:na] at org.springframework.data.mapping.PropertyPath.create(PropertyPath .java:327)〜[spring-data-commons-1.11.0.RELEASE.jar:na] org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:307)〜[spring-data-commons- 1.11.0.RELEASE.jar:na] at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:270)〜[spring-data-commons-1.11.0.RELEASE.jar:na] at org. springframework.data.mapping.PropertyPath.from(PropertyPath.java:241)〜[spring-data-commons-1.11.0.RELEASE.jar:na] at org.springframework.data.repository.query.parser.Part.( Part.java:76)〜[spring-data-commons-1.11.0.RELEASE.jar:
它们在禁用任何一个时都有效.
该项目基于Spring Boot 1.3.0.M5.
这是一个重现情况的示例项目:
https://github.com/izeye/spring-boot-throwaway-branches/tree/data-jpa-and-elasticsearch
Ken*_*ani 19
在Spring数据存储库的数据源无关,这意味着JpaRepository和ElasticsearchRepository两卷成Repository接口.在这种情况下,Spring Boot的自动配置将导致Spring Data JPA尝试为项目中的每个存储库配置一个bean,该存储库继承任何Spring Data Commons基本存储库.
要解决此问题,您需要将JPA存储库和Elasticsearch存储库移动到单独的包中,并确保使用以下命令注释您的@SpringBootApplication应用程序类:
@EnableJpaRepositories@EnableElasticsearchRepositories然后,您需要为每个启用注释指定存储库的位置.这最终看起来像:
@SpringBootApplication
@EnableJpaRepositories("com.izeye.throwaway.data")
@EnableElasticsearchRepositories("com.izeye.throwaway.indexing")
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
然后,您的应用程序将能够消除哪些存储库用于哪个Spring Data项目的歧义.
你可以像这样使用:
@Configuration
@EnableTransactionManagement
@EnableJpaRepositories(excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ElasticsearchCrudRepository.class))
@EnableElasticsearchRepositories(includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ElasticsearchCrudRepository.class))
public class DataConfiguration {
    ...
}
或者在SpringBoot中:
@SpringBootApplication
@EnableJpaRepositories(excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ElasticsearchCrudRepository.class))
@EnableElasticsearchRepositories(includeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = ElasticsearchCrudRepository.class))
public class MyApplication {
    ...
}
| 归档时间: | 
 | 
| 查看次数: | 8124 次 | 
| 最近记录: |