SpringBoot 애플리케이션에서 SpringData JPA 및 SpringData Elastic 검색 리포지토리를 동일한 도메인 클래스에서 어떻게 사용합니까?
Spring Data JPA와 Spring Data Elastic 검색을 동일한 도메인 객체에서 모두 사용하려고 하는데 작동하지 않습니다.
간단한 테스트를 실행하려고 했을 때 다음과 같은 예외가 발생했습니다.
org.springframework.data.sys.속성 참조 예외:org.springframework.data.mapping에서 Person! 유형에 대한 속성 인덱스를 찾을 수 없습니다.속성 경로.(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] at 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:na] at org.springframework.data.repository.query.parser.PartTree$OrPart입니다.(PartTree.java:235) ~[spring-data-commons-1.11.0.release.jar:na] at org.springframework.data.repository.query.parser.PartTree$Predicate.빌드 트리(PartTree.java:373) ~[spring-data-commons-1.11.0.release.jar:na] at org.springframework.data.repository.query.parser.PartTree$Predicate.(PartTree.java:353) ~[spring-data-commons-1.11.0.release.jar:na] at org.springframework.data.repository.query.parser.파트 트리.(PartTree.java:84) ~[spring-data-commons-1.11.0.release.jar:na] at org.springframework.data.jpa.repository.query.PartTreeJpaQuery.(PartTreeJpaQuery.java:61) ~[spring-data-jpa-1.9.0.release.jar:na] at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy).java:95) ~[spring-data-jpa-1.9.0.release.jar:na] at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$CreateIfFoundQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy).java:java) ~[spring-data-jpa-1.9.0.release.jar:na] at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy).java:73) ~[spring-data-jpa-1.9.0.release.jar:na] at org.springframework.data.repository.core.support.리포지토리 팩토리 지원$쿼리 실행자 방법요격기.(RespositoryFactorySupport.java:408) ~[spring-data-commons-1.11.0.release.jar:na] at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:206) ~[spring-data-commons-1.11.0.release.jar:na] at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:251) ~[spring-data-commons-1.11.0.release.jar:na] at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:237) ~[spring-data-commons-1.11.0.release.jar:na] at org.springframework.data.jpa.repository.지지하다.JpaRepositoryFactoryBean.afterPropertiesSet(JpaRepositoryFactoryBean.java:92) ~[spring-data-jpa-1.9.0.0.org.springframework에서 RELEASE.jar:na].콩 공장지지하다.추상적인Autowire Capable Bean Factory.invokeInit 메서드(추상)오토와이어 Capable Bean Factory.java:1637) ~[봄-콩-4.2.1.org.spring framework에서 RELEASE.jar:4.2.1.REASE].콩 공장지지하다.추상적인Autowire Capable Bean Factory.초기화 Bean(추상)오토와이어 Capable Bean Factory.java:1574) ~[봄-콩-4.2.1.RELEASE.jar:4.2.1.REASE] ... 43개 공통 프레임 누락
둘 중 하나를 비활성화할 때 작동합니다.
이 프로젝트는 Spring Boot 1.3.0을 기반으로 합니다.M5.
다음은 상황을 재현하는 샘플 프로젝트입니다.
https://github.com/izeye/spring-boot-throwaway-branches/tree/data-jpa-and-elasticsearch
구애받지 않습니다. 즉, Spring Data는 데이터 소스에 구애받지 않습니다.JpaRepository
그리고.ElasticsearchRepository
둘 다 로 굴러가다.Repository
경우저장소를 의 각 합니다.이경 SpringBoot 를동성구하면로으자 SpringDataJPA가 SpringDataCommon 기본 리포지토리를 상속하는 프로젝트의 각 리포지토리에 대해 bean을 구성하려고 시도합니다.
하고 "Elastic JPA"에 .@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 {
...
}
언급URL : https://stackoverflow.com/questions/32878813/how-do-you-use-both-spring-data-jpa-and-spring-data-elasticsearch-repositories-o
'sourcecode' 카테고리의 다른 글
데이터 테이블에 AsEnumberable에 대한 정의가 없습니다. (0) | 2023.08.22 |
---|---|
C# 문자열.IsNullOrEmpty Javascript 등가 (0) | 2023.08.22 |
MySQL에서 합계()로 주문하려면 어떻게 해야 합니까? (0) | 2023.08.22 |
Oracle 테이블 동의어에서 최대 절전 모드 스키마 유효성 검사 실패 (0) | 2023.08.22 |
PHP로 디렉토리를 쓸 수 있는지 확인하려면 어떻게 해야 합니까? (0) | 2023.08.22 |