0

내 스프링 부팅 응용 프로그램에서 Elasticsearch를 통해 퍼지 검색을 구현하려고합니다.스프링 데이터 탄성 검색 cusom 저장소

@Profile("test") 
@Configuration 
@EnableElasticsearchRepositories(basePackages = "com.example.domain.repository.elasticsearch") 
public class ElasticsearchTestConfig { 
} 

내가 저장소를 가지고 :

내 ES의 설정입니다

@Repository 
public interface ESDecisionRepository extends ElasticsearchRepository<ESDecision, String>, ESDecisionRepositoryCustom { 
} 

나는 사용자 정의 저장소를 생성 한 퍼지 검색 할 수 있도록하기 위해 :

public interface ESDecisionRepositoryCustom { 

    public List<ESDecision> findFuzzyBySearchTerm(String searchTerm); 

} 

및 맞춤 구현을 제공했습니다.

내 응용 프로그램을 시작하는 동안 6,

지금

@Repository 
public class ESDecisionRepositoryCustomImpl implements ESDecisionRepositoryCustom { 

    @Autowired 
    protected ElasticsearchTemplate elasticsearchTemplate; 

    @Override 
    public List<ESDecision> findFuzzyBySearchTerm(String searchTerm) { 
     Criteria c = new Criteria("name").fuzzy(searchTerm); 
     return elasticsearchTemplate.queryForList(new CriteriaQuery(c), ESDecision.class); 
    } 

} 
는 다음과 같은 예외와 함께 실패합니다

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ESDecisionRepository': Invocation of init method failed; nested exception is org.springframework.data.mapping.PropertyReferenceException: No property searchTerm found for type ESDecision! 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1628) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:483) 
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) 
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) 
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) 
    at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:208) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138) 
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1066) 
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:585) 
    ... 43 common frames omitted 
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property searchTerm found for type ESDecision! 
    at org.springframework.data.mapping.PropertyPath.<init>(PropertyPath.java:77) 
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:329) 
    at org.springframework.data.mapping.PropertyPath.create(PropertyPath.java:309) 
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:272) 
    at org.springframework.data.mapping.PropertyPath.from(PropertyPath.java:243) 
    at org.springframework.data.repository.query.parser.Part.<init>(Part.java:76) 
    at org.springframework.data.repository.query.parser.PartTree$OrPart.<init>(PartTree.java:247) 
    at org.springframework.data.repository.query.parser.PartTree$Predicate.buildTree(PartTree.java:398) 
    at org.springframework.data.repository.query.parser.PartTree$Predicate.<init>(PartTree.java:378) 
    at org.springframework.data.repository.query.parser.PartTree.<init>(PartTree.java:89) 
    at org.springframework.data.elasticsearch.repository.query.ElasticsearchPartQuery.<init>(ElasticsearchPartQuery.java:44) 
    at org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactory$ElasticsearchQueryLookupStrategy.resolveQuery(ElasticsearchRepositoryFactory.java:119) 
    at org.springframework.data.repository.core.support.RepositoryFactorySupport$QueryExecutorMethodInterceptor.<init>(RepositoryFactorySupport.java:436) 
    at org.springframework.data.repository.core.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:221) 
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.initAndReturn(RepositoryFactoryBeanSupport.java:277) 
    at org.springframework.data.repository.core.support.RepositoryFactoryBeanSupport.afterPropertiesSet(RepositoryFactoryBeanSupport.java:263) 
    at org.springframework.data.elasticsearch.repository.support.ElasticsearchRepositoryFactoryBean.afterPropertiesSet(ElasticsearchRepositoryFactoryBean.java:67) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1687) 
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1624) 
    ... 53 common frames omitted 

은 내가 뭘 잘못하고 어떻게 문제를 해결하는 방법입니까?

+0

'ESDecision' 엔티티 클래스에'searchTerm' 속성이 있습니까? –

+0

아니요, 그런 속성이 없습니다 – alexanoid

+1

맞춤형 저장소 구현 이름을 'ESDecisionRepositoryImpl'로 변경해보세요. 커스텀 리포지터리 (custom repository) 구현을위한 네이밍 규칙이 있으며 그것을 작동시키기 위해서는 그것을 따라야합니다. [docs] (http://docs.spring.io/spring-data/jpa/docs/current/reference/html/#repositories.single-repository-behaviour) –

답변

1

사용자 정의 저장소 구현 클래스 이름을 ESDecisionRepositoryCustomImpl에서 ESDecisionRepositoryImpl으로 변경하십시오. 그것은 (아래 참조)의 핵심 저장소 인터페이스에 비해에서 클래스의 가장 중요한 비트를 찾을 수있는 문서

에서

이름의 IMPL 접미사입니다.

사용자 지정 리포지토리 구현 작업을하기 위해 따라야하는 명명 규칙이 있습니다. docs

이 시도 체크 아웃 :이 도움이

@Repository 
public class ESDecisionRepositoryCustomImpl implements ESDecisionRepositoryCustom { 

    @Autowired 
    protected ElasticsearchTemplate elasticsearchTemplate; 

    @Override 
    public List<ESDecision> findFuzzyBySearchTerm(String searchTerm) { 
     Criteria c = new Criteria("name").fuzzy(searchTerm); 
     return elasticsearchTemplate.queryForList(new CriteriaQuery(c), ESDecision.class); 
    } 

} 

희망을.

관련 문제