springboot+elasticsearch 报错

错误1: .d.e.r.s.AbstractElasticsearchRepository : failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []

次报错是由于配置文件application.properties里面打开了一下注释

spring.data.elasticsearch.cluster-name=elasticsearch

spring.data.elasticsearch.cluster-nodes=127.0.0.1:9200

spring.data.elasticsearch.properties.path.logs=./elasticsearch/log
spring.data.elasticsearch.properties.path.logs=./elasticsearch/data

错误2:包名不一致引起的报错
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'Test.ElasticSearchTest': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private inter.ArticleSearchRepository

当修改每个包的名称后,也即统一包名开头后,成功运行。

成功运行截图如下:

总结原因:application.java启动类一定要放在com包,也就是根目录下的一个包下,不能放在和其他三个包并列的包里面,切记!!找了一晚上的原因。
还有下图是变幻包视图结构。

原文地址:https://www.cnblogs.com/Andrew520/p/7795090.html