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

在SpringBoot应用中,尝试集成Elasticsearch 7.x时,出现ElasticSearchTemplate自动注入失败的问题。错误信息显示没有找到符合条件的bean。解决方案是将@Autowired的ElasticSearchTemplate替换为ElasticSearchRestTemplate,因为7.x版本已弃用前者。更新依赖后,使用ElasticSearchRestTemplate即可解决该问题。

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。
希望能帮到你

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值