Springboot集成elasticsearch 报扫描不到Repository

项目依赖

    
        org.springframework.boot
        spring-boot-starter-parent
        2.0.0.RELEASE
         
    
    
    
        org.springframework.boot
        spring-boot-starter-data-elasticearch
    

项目结构

Springboot集成elasticsearch 报扫描不到Repository_第1张图片

Repository代码

package com.allqj.learner_autonomy.base.repository;

import com.allqj.learner_autonomy.base.entity.es.StudentES;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;

public interface IStudentRepository extends ElasticsearchRepository {

}

项目启动不了原因

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2019-02-14 18:34:07.085 ERROR 2364 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Field iStudentRepository in com.allqj.learner_autonomy.base.service.impl.StudentServiceImpl required a bean of type 'com.allqj.learner_autonomy.base.repository.IStudentRepository' that could not be found.


Action:

Consider defining a bean of type 'com.allqj.learner_autonomy.base.repository.IStudentRepository' in your configuration.


Process finished with exit code 1

其中试过加@Component和@Repository注解 但是都没用。

解决办法:在启动类添加注解@EnableElasticsearchRepositories(basePackages = “xxx.xxx.xxx”)

问题解决

你可能感兴趣的:(Java异常)