SpringBoot集成Es使用ElasticSearchTemplate7.x版本自动注入失败解决
错误:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type ‘org.springframework.data.elasticsearch.core.ElasticsearchTemplate’ available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1695)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1253)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1207)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:640)
… 28 more
解决方案:可能是spring-data-es版本问题
把自动注入的ElasticSearchTemplate换成ElasticSearchRestTemplate就可以了

通过查阅资料得知:springboot集成es的版本更新很快,在7.x版本已经弃用了ElasticSearchTemplate,进而使用ElasticSearchRestTemplate。
希望能帮到你
在SpringBoot应用中,尝试集成Elasticsearch 7.x时,出现ElasticSearchTemplate自动注入失败的问题。错误信息显示没有找到符合条件的bean。解决方案是将@Autowired的ElasticSearchTemplate替换为ElasticSearchRestTemplate,因为7.x版本已弃用前者。更新依赖后,使用ElasticSearchRestTemplate即可解决该问题。

1万+

被折叠的 条评论
为什么被折叠?



